summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--java/com/android/voicemail/AndroidManifest.xml8
-rw-r--r--java/com/android/voicemail/VoicemailClient.java6
-rw-r--r--java/com/android/voicemail/VoicemailPowerCycleReceiver.java38
-rw-r--r--java/com/android/voicemail/impl/AndroidManifest.xml7
-rw-r--r--java/com/android/voicemail/impl/OmtpService.java52
-rw-r--r--java/com/android/voicemail/impl/VoicemailBootReceiver.java31
-rw-r--r--java/com/android/voicemail/impl/VoicemailClientImpl.java14
-rw-r--r--java/com/android/voicemail/stub/StubVoicemailClient.java6
8 files changed, 118 insertions, 44 deletions
diff --git a/java/com/android/voicemail/AndroidManifest.xml b/java/com/android/voicemail/AndroidManifest.xml
index 35beaf359..817cf1b55 100644
--- a/java/com/android/voicemail/AndroidManifest.xml
+++ b/java/com/android/voicemail/AndroidManifest.xml
@@ -41,5 +41,13 @@
<data android:scheme="android_secret_code" />
</intent-filter>
</receiver>
+
+ <receiver android:name="com.android.voicemail.VoicemailPowerCycleReceiver"
+ android:exported="false">
+ <intent-filter>
+ <action android:name="android.intent.action.BOOT_COMPLETED" />
+ <action android:name="android.intent.action.ACTION_SHUTDOWN" />
+ </intent-filter>
+ </receiver>
</application>
</manifest>
diff --git a/java/com/android/voicemail/VoicemailClient.java b/java/com/android/voicemail/VoicemailClient.java
index 847919a30..28d2bf0ff 100644
--- a/java/com/android/voicemail/VoicemailClient.java
+++ b/java/com/android/voicemail/VoicemailClient.java
@@ -142,4 +142,10 @@ public interface VoicemailClient {
@NonNull
PersistableBundle getConfig(
@NonNull Context context, @Nullable PhoneAccountHandle phoneAccountHandle);
+
+ @MainThread
+ void onBoot(@NonNull Context context);
+
+ @MainThread
+ void onShutdown(@NonNull Context context);
}
diff --git a/java/com/android/voicemail/VoicemailPowerCycleReceiver.java b/java/com/android/voicemail/VoicemailPowerCycleReceiver.java
new file mode 100644
index 000000000..e9362b42d
--- /dev/null
+++ b/java/com/android/voicemail/VoicemailPowerCycleReceiver.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2017 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.voicemail;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import com.android.dialer.common.Assert;
+
+/** Receives {@link Intent#ACTION_BOOT_COMPLETED} and {@link Intent#ACTION_SHUTDOWN} */
+public class VoicemailPowerCycleReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ VoicemailClient voicemailClient = VoicemailComponent.get(context).getVoicemailClient();
+ if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
+ voicemailClient.onBoot(context);
+ } else if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {
+ voicemailClient.onShutdown(context);
+ } else {
+ throw Assert.createAssertionFailException("unexpected action: " + intent.getAction());
+ }
+ }
+}
diff --git a/java/com/android/voicemail/impl/AndroidManifest.xml b/java/com/android/voicemail/impl/AndroidManifest.xml
index 3c7df66fa..d3c7a4a01 100644
--- a/java/com/android/voicemail/impl/AndroidManifest.xml
+++ b/java/com/android/voicemail/impl/AndroidManifest.xml
@@ -113,13 +113,6 @@
android:windowSoftInputMode="stateVisible|adjustResize">
</activity>
- <receiver android:name="com.android.voicemail.impl.VoicemailBootReceiver"
- android:exported="false">
- <intent-filter>
- <action android:name="android.intent.action.BOOT_COMPLETED" />
- </intent-filter>
- </receiver>
-
<receiver android:name="com.android.voicemail.impl.PackageReplacedReceiver"
android:exported="false">
<intent-filter>
diff --git a/java/com/android/voicemail/impl/OmtpService.java b/java/com/android/voicemail/impl/OmtpService.java
index b82cc5f68..4db1aeb7e 100644
--- a/java/com/android/voicemail/impl/OmtpService.java
+++ b/java/com/android/voicemail/impl/OmtpService.java
@@ -17,9 +17,13 @@
package com.android.voicemail.impl;
import android.annotation.TargetApi;
+import android.content.Context;
import android.content.Intent;
import android.os.Build.VERSION_CODES;
import android.os.UserManager;
+import android.preference.PreferenceManager;
+import android.support.annotation.MainThread;
+import android.support.annotation.NonNull;
import android.telecom.PhoneAccountHandle;
import android.telephony.VisualVoicemailService;
import android.telephony.VisualVoicemailSms;
@@ -40,6 +44,8 @@ public class OmtpService extends VisualVoicemailService {
public static final String EXTRA_VOICEMAIL_SMS = "extra_voicemail_sms";
+ private static final String IS_SHUTTING_DOWN = "com.android.voicemail.impl.is_shutting_down";
+
@Override
public void onCellServiceConnected(
VisualVoicemailTask task, final PhoneAccountHandle phoneAccountHandle) {
@@ -50,7 +56,7 @@ public class OmtpService extends VisualVoicemailService {
return;
}
- if (!isUserUnlocked()) {
+ if (!isUserUnlocked(this)) {
VvmLog.i(TAG, "onCellServiceConnected: user locked");
task.finish();
return;
@@ -75,7 +81,7 @@ public class OmtpService extends VisualVoicemailService {
return;
}
- if (!isUserUnlocked()) {
+ if (!isUserUnlocked(this)) {
LegacyModeSmsHandler.handle(this, sms);
return;
}
@@ -105,12 +111,18 @@ public class OmtpService extends VisualVoicemailService {
return;
}
- if (!isUserUnlocked()) {
+ if (!isUserUnlocked(this)) {
VvmLog.i(TAG, "onSimRemoved: user locked");
task.finish();
return;
}
+ if (isShuttingDown(this)) {
+ VvmLog.i(TAG, "onSimRemoved: system shutting down, ignoring");
+ task.finish();
+ return;
+ }
+
Logger.get(this).logImpression(DialerImpression.Type.VVM_UNBUNDLED_EVENT_RECEIVED);
VvmAccountManager.removeAccount(this, phoneAccountHandle);
task.finish();
@@ -124,7 +136,7 @@ public class OmtpService extends VisualVoicemailService {
task.finish();
return;
}
- if (!isUserUnlocked()) {
+ if (!isUserUnlocked(this)) {
VvmLog.i(TAG, "onStopped: user locked");
task.finish();
return;
@@ -132,6 +144,22 @@ public class OmtpService extends VisualVoicemailService {
Logger.get(this).logImpression(DialerImpression.Type.VVM_UNBUNDLED_EVENT_RECEIVED);
}
+ @MainThread
+ static void onBoot(@NonNull Context context) {
+ VvmLog.i(TAG, "onBoot");
+ Assert.isTrue(isUserUnlocked(context));
+ Assert.isMainThread();
+ setShuttingDown(context, false);
+ }
+
+ @MainThread
+ static void onShutdown(@NonNull Context context) {
+ VvmLog.i(TAG, "onShutdown");
+ Assert.isTrue(isUserUnlocked(context));
+ Assert.isMainThread();
+ setShuttingDown(context, true);
+ }
+
private boolean isModuleEnabled() {
return VoicemailComponent.get(this).getVoicemailClient().isVoicemailModuleEnabled();
}
@@ -150,8 +178,20 @@ public class OmtpService extends VisualVoicemailService {
return true;
}
- private boolean isUserUnlocked() {
- UserManager userManager = getSystemService(UserManager.class);
+ private static boolean isUserUnlocked(@NonNull Context context) {
+ UserManager userManager = context.getSystemService(UserManager.class);
return userManager.isUserUnlocked();
}
+
+ private static void setShuttingDown(Context context, boolean value) {
+ PreferenceManager.getDefaultSharedPreferences(context)
+ .edit()
+ .putBoolean(IS_SHUTTING_DOWN, value)
+ .apply();
+ }
+
+ private static boolean isShuttingDown(Context context) {
+ return PreferenceManager.getDefaultSharedPreferences(context)
+ .getBoolean(IS_SHUTTING_DOWN, false);
+ }
}
diff --git a/java/com/android/voicemail/impl/VoicemailBootReceiver.java b/java/com/android/voicemail/impl/VoicemailBootReceiver.java
deleted file mode 100644
index 0a3e61a01..000000000
--- a/java/com/android/voicemail/impl/VoicemailBootReceiver.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * Copyright (C) 2017 The Android Open Source Project
- *
- * <p>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
- *
- * <p>http://www.apache.org/licenses/LICENSE-2.0
- *
- * <p>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.voicemail.impl;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import com.android.voicemail.VoicemailComponent;
-
-/** Receives {@link Intent#ACTION_BOOT_COMPLETED} for the voicemail module. */
-public class VoicemailBootReceiver extends BroadcastReceiver {
-
- @Override
- public void onReceive(Context context, Intent intent) {
- if (!VoicemailComponent.get(context).getVoicemailClient().isVoicemailModuleEnabled()) {
- return;
- }
- StatusCheckJobService.schedule(context);
- }
-}
diff --git a/java/com/android/voicemail/impl/VoicemailClientImpl.java b/java/com/android/voicemail/impl/VoicemailClientImpl.java
index 96cd5344f..1b9890381 100644
--- a/java/com/android/voicemail/impl/VoicemailClientImpl.java
+++ b/java/com/android/voicemail/impl/VoicemailClientImpl.java
@@ -20,6 +20,7 @@ import android.os.Build.VERSION_CODES;
import android.os.PersistableBundle;
import android.provider.VoicemailContract.Status;
import android.provider.VoicemailContract.Voicemails;
+import android.support.annotation.MainThread;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.os.BuildCompat;
@@ -141,6 +142,19 @@ public class VoicemailClientImpl implements VoicemailClient {
return new OmtpVvmCarrierConfigHelper(context, phoneAccountHandle).getConfig();
}
+ @Override
+ @MainThread
+ public void onBoot(@NonNull Context context) {
+ OmtpService.onBoot(context);
+ StatusCheckJobService.schedule(context);
+ }
+
+ @Override
+ @MainThread
+ public void onShutdown(@NonNull Context context) {
+ OmtpService.onShutdown(context);
+ }
+
@TargetApi(VERSION_CODES.O)
@Override
public void appendOmtpVoicemailSelectionClause(
diff --git a/java/com/android/voicemail/stub/StubVoicemailClient.java b/java/com/android/voicemail/stub/StubVoicemailClient.java
index 9a89e30c0..e5d51455c 100644
--- a/java/com/android/voicemail/stub/StubVoicemailClient.java
+++ b/java/com/android/voicemail/stub/StubVoicemailClient.java
@@ -93,4 +93,10 @@ public final class StubVoicemailClient implements VoicemailClient {
@NonNull Context context, @Nullable PhoneAccountHandle phoneAccountHandle) {
return new PersistableBundle();
}
+
+ @Override
+ public void onBoot(@NonNull Context context) {}
+
+ @Override
+ public void onShutdown(@NonNull Context context) {}
}