Merge "Never disable ViewInfoActivity" into nyc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index f14c4b1..9c8a25b 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -20,7 +20,6 @@
     <uses-permission android:name="android.permission.CALL_PHONE" />
     <uses-permission android:name="android.permission.READ_CONTACTS" />
     <uses-permission android:name="android.permission.MANAGE_USERS" />
-    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
 
     <application
         android:defaultToDeviceProtectedStorage="true"
@@ -57,13 +56,6 @@
             </intent-filter>
         </activity>
 
-        <receiver
-            android:name=".BootReceiver">
-            <intent-filter>
-                <action android:name="android.intent.action.BOOT_COMPLETED" />
-                <category android:name="android.intent.category.DEFAULT" />
-            </intent-filter>
-        </receiver>
     </application>
 
 </manifest>
diff --git a/src/com/android/emergency/BootReceiver.java b/src/com/android/emergency/BootReceiver.java
deleted file mode 100644
index d2dc114..0000000
--- a/src/com/android/emergency/BootReceiver.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.emergency;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-
-import com.android.emergency.view.ViewInfoActivity;
-
-/**
- * Broadcast receiver which handles the BOOT_COMPLETED intent and enables or disables
- * {@link ViewInfoActivity} depending on information being available.
- */
-public class BootReceiver extends BroadcastReceiver {
-    @Override
-    public void onReceive(Context context, Intent intent) {
-        if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
-            PackageManagerUtils.disableViewInfoActivityIfNoInfoAvailable(context);
-        }
-    }
-}
diff --git a/src/com/android/emergency/PackageManagerUtils.java b/src/com/android/emergency/PackageManagerUtils.java
deleted file mode 100644
index f392061..0000000
--- a/src/com/android/emergency/PackageManagerUtils.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.emergency;
-
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.pm.PackageManager;
-
-import com.android.emergency.edit.EditEmergencyInfoFragment;
-import com.android.emergency.view.ViewEmergencyContactsFragment;
-import com.android.emergency.view.ViewInfoActivity;
-
-/**
- * Utils related to {@link PackageManager}.
- */
-public class PackageManagerUtils {
-
-    /**
-     * Disables {@link ViewInfoActivity} if no emergency information or emergency contacts were
-     * input by the user. Otherwise, it enables it.
-     */
-    public static void disableViewInfoActivityIfNoInfoAvailable(Context context) {
-        // Enable ViewInfoActivity if the user input some info. Otherwise, disable it.
-        PackageManager pm = context.getPackageManager();
-        if (ViewEmergencyContactsFragment.hasAtLeastOneEmergencyContact(context)
-                || EditEmergencyInfoFragment.hasAtLeastOnePreferenceSet(context)) {
-            pm.setComponentEnabledSetting(new ComponentName(context, ViewInfoActivity.class),
-                    PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
-        } else {
-            pm.setComponentEnabledSetting(new ComponentName(context, ViewInfoActivity.class),
-                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
-        }
-    }
-
-    private PackageManagerUtils() {
-        // Prevent instantiation
-        throw new UnsupportedOperationException();
-    }
-}
diff --git a/src/com/android/emergency/edit/EditEmergencyInfoFragment.java b/src/com/android/emergency/edit/EditEmergencyInfoFragment.java
index 8910d15..042142d 100644
--- a/src/com/android/emergency/edit/EditEmergencyInfoFragment.java
+++ b/src/com/android/emergency/edit/EditEmergencyInfoFragment.java
@@ -74,23 +74,6 @@
         }
     }
 
-    /** Returns true if there is at least one preference set. */
-    public static boolean hasAtLeastOnePreferenceSet(Context context) {
-        SharedPreferences sharedPreferences =
-                PreferenceManager.getDefaultSharedPreferences(context);
-        for (String key : PreferenceKeys.KEYS_EDIT_EMERGENCY_INFO) {
-            if (key.equals(PreferenceKeys.KEY_DATE_OF_BIRTH)) {
-                if (sharedPreferences.getLong(key, BirthdayPreference.DEFAULT_UNSET_VALUE)
-                        != BirthdayPreference.DEFAULT_UNSET_VALUE) {
-                    return true;
-                }
-            } else if (!TextUtils.isEmpty(sharedPreferences.getString(key, ""))) {
-                return true;
-            }
-        }
-        return false;
-    }
-
     @Override
     public void onResume() {
         super.onResume();
diff --git a/src/com/android/emergency/edit/EditInfoActivity.java b/src/com/android/emergency/edit/EditInfoActivity.java
index 0931fcc..f4dfb45 100644
--- a/src/com/android/emergency/edit/EditInfoActivity.java
+++ b/src/com/android/emergency/edit/EditInfoActivity.java
@@ -32,7 +32,6 @@
 import android.view.MenuItem;
 
 import com.android.emergency.EmergencyTabActivity;
-import com.android.emergency.PackageManagerUtils;
 import com.android.emergency.PreferenceKeys;
 import com.android.emergency.R;
 import com.android.internal.logging.MetricsLogger;
@@ -80,12 +79,6 @@
     }
 
     @Override
-    public void onPause() {
-        super.onPause();
-        PackageManagerUtils.disableViewInfoActivityIfNoInfoAvailable(this);
-    }
-
-    @Override
     public boolean onCreateOptionsMenu(Menu menu) {
         MenuInflater inflater = getMenuInflater();
         inflater.inflate(R.menu.edit_info_menu, menu);
diff --git a/src/com/android/emergency/preferences/EmergencyContactsPreference.java b/src/com/android/emergency/preferences/EmergencyContactsPreference.java
index 44dfddd..968b301 100644
--- a/src/com/android/emergency/preferences/EmergencyContactsPreference.java
+++ b/src/com/android/emergency/preferences/EmergencyContactsPreference.java
@@ -205,7 +205,7 @@
             String emergencyContactStrings = serialize(filteredEmergencyContacts);
             SharedPreferences sharedPreferences =
                     PreferenceManager.getDefaultSharedPreferences(context);
-            sharedPreferences.edit().putString(key, emergencyContactStrings).apply();
+            sharedPreferences.edit().putString(key, emergencyContactStrings).commit();
         }
         return filteredEmergencyContacts;
     }
diff --git a/tests/src/com/android/emergency/view/ViewInfoActivityTest.java b/tests/src/com/android/emergency/view/ViewInfoActivityTest.java
index ebbea22..7d3f2b9 100644
--- a/tests/src/com/android/emergency/view/ViewInfoActivityTest.java
+++ b/tests/src/com/android/emergency/view/ViewInfoActivityTest.java
@@ -59,7 +59,6 @@
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        enableActivity();
         mPersonalCard = (LinearLayout)  getActivity().findViewById(R.id.name_and_dob_linear_layout);
         mPersonalCardLargeItem = (TextView)  getActivity().findViewById(R.id.personal_card_large);
         mPersonalCardSmallItem = (TextView)  getActivity().findViewById(R.id.personal_card_small);
@@ -278,15 +277,4 @@
         });
         getInstrumentation().waitForIdleSync();
     }
-
-    private void enableActivity() {
-        // This activity is disabled when no info is set by the EditInfoActivity. We enable it here
-        // for the tests.
-        PackageManager pm = getInstrumentation().getContext().getPackageManager();
-        final ComponentName mComponentName =
-                new ComponentName("com.android.emergency",
-                        "com.android.emergency.view.ViewInfoActivity");
-        pm.setComponentEnabledSetting(mComponentName,
-                PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
-    }
 }