summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-02-11 21:10:49 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-02-11 21:10:49 +0000
commitc2fc9aff5ec0b99c34364fb2427bee6c6462d769 (patch)
treeb00ef4c536333504fb2ad9ed3ccd2ec9c312ac49
parentab1cf45500c741a8f31437188df46168025a2dee (diff)
parent5d8a556e3e4208ef38120ba728cd1e317f74f663 (diff)
downloadStk-c2fc9aff5ec0b99c34364fb2427bee6c6462d769.tar.gz
Merge "Use new @System API in ActivityManager to monitor screen being idle." am: 5d8a556e3e
Change-Id: Ie8e05e6a05492674929d5d012a97fbe55b66e58f
-rw-r--r--src/com/android/stk/StkAppService.java79
1 files changed, 32 insertions, 47 deletions
diff --git a/src/com/android/stk/StkAppService.java b/src/com/android/stk/StkAppService.java
index 4a254ed..0543a24 100644
--- a/src/com/android/stk/StkAppService.java
+++ b/src/com/android/stk/StkAppService.java
@@ -19,6 +19,7 @@ package com.android.stk;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.app.AlertDialog;
+import android.app.HomeVisibilityObserver;
import android.app.KeyguardManager;
import android.app.Notification;
import android.app.NotificationChannel;
@@ -26,7 +27,6 @@ import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.app.Activity;
-import android.app.ActivityManagerNative;
import android.app.IProcessObserver;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -70,8 +70,6 @@ import android.widget.TextView;
import android.widget.Toast;
import android.content.IntentFilter;
-import androidx.localbroadcastmanager.content.LocalBroadcastManager;
-
import com.android.internal.telephony.PhoneConfigurationManager;
import com.android.internal.telephony.cat.AppInterface;
import com.android.internal.telephony.cat.Input;
@@ -103,6 +101,8 @@ import static com.android.internal.telephony.cat.CatCmdMessage.
import static com.android.internal.telephony.cat.CatCmdMessage.
SetupEventListConstants.USER_ACTIVITY_EVENT;
+import androidx.localbroadcastmanager.content.LocalBroadcastManager;
+
/**
* SIM toolkit application level service. Interacts with Telephopny messages,
* application's launch and user input from STK UI elements.
@@ -180,7 +180,7 @@ public class StkAppService extends Service implements Runnable {
private AppInterface[] mStkService = null;
private StkContext[] mStkContext = null;
private int mSimCount = 0;
- private IProcessObserver.Stub mProcessObserver = null;
+ private HomeVisibilityObserver mHomeVisibilityObserver = null;
private BroadcastReceiver mLocaleChangeReceiver = null;
private TonePlayer mTonePlayer = null;
private Vibrator mVibrator = null;
@@ -411,7 +411,7 @@ public class StkAppService extends Service implements Runnable {
public void onDestroy() {
CatLog.d(LOG_TAG, "onDestroy()");
unregisterUserActivityReceiver();
- unregisterProcessObserver();
+ unregisterHomeVisibilityObserver();
unregisterLocaleChangeReceiver();
unregisterHomeKeyEventReceiver();
sInstance = null;
@@ -1173,7 +1173,7 @@ public class StkAppService extends Service implements Runnable {
CatLog.d(LOG_TAG, "set up idle mode");
launchIdleText(slotId);
} else {
- registerProcessObserver();
+ registerHomeVisibilityObserver();
}
}
break;
@@ -1788,7 +1788,7 @@ public class StkAppService extends Service implements Runnable {
unregisterUserActivityReceiver();
break;
case IDLE_SCREEN_AVAILABLE_EVENT:
- unregisterProcessObserver(AppInterface.CommandType.SET_UP_EVENT_LIST, slotId);
+ unregisterHomeVisibilityObserver(AppInterface.CommandType.SET_UP_EVENT_LIST, slotId);
break;
case LANGUAGE_SELECTION_EVENT:
unregisterLocaleChangeReceiver();
@@ -1808,7 +1808,7 @@ public class StkAppService extends Service implements Runnable {
registerUserActivityReceiver();
break;
case IDLE_SCREEN_AVAILABLE_EVENT:
- registerProcessObserver();
+ registerHomeVisibilityObserver();
break;
case LANGUAGE_SELECTION_EVENT:
registerLocaleChangeReceiver();
@@ -1850,37 +1850,25 @@ public class StkAppService extends Service implements Runnable {
}
}
- private synchronized void registerProcessObserver() {
- if (mProcessObserver == null) {
- try {
- IProcessObserver.Stub observer = new IProcessObserver.Stub() {
- @Override
- public void onForegroundActivitiesChanged(int pid, int uid, boolean fg) {
- if (isScreenIdle()) {
- Message message = mServiceHandler.obtainMessage(OP_IDLE_SCREEN);
- mServiceHandler.sendMessage(message);
- unregisterProcessObserver();
- }
- }
-
- @Override
- public void onForegroundServicesChanged(int pid, int uid, int fgServiceTypes) {
- }
-
- @Override
- public void onProcessDied(int pid, int uid) {
+ private synchronized void registerHomeVisibilityObserver() {
+ if (mHomeVisibilityObserver == null) {
+ mHomeVisibilityObserver = new HomeVisibilityObserver() {
+ @Override
+ public void onHomeVisibilityChanged(boolean isHomeActivityVisible) {
+ if (isHomeActivityVisible) {
+ Message message = mServiceHandler.obtainMessage(OP_IDLE_SCREEN);
+ mServiceHandler.sendMessage(message);
+ unregisterHomeVisibilityObserver();
}
- };
- ActivityManagerNative.getDefault().registerProcessObserver(observer);
- CatLog.d(LOG_TAG, "Started to observe the foreground activity");
- mProcessObserver = observer;
- } catch (RemoteException e) {
- CatLog.e(LOG_TAG, "Failed to register the process observer");
- }
+ }
+ };
+ ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
+ am.registerHomeVisibilityObserver(mHomeVisibilityObserver);
+ CatLog.d(LOG_TAG, "Started to observe the foreground activity");
}
}
- private void unregisterProcessObserver(AppInterface.CommandType command, int slotId) {
+ private void unregisterHomeVisibilityObserver(AppInterface.CommandType command, int slotId) {
// Check if there is any pending command which still needs the process observer
// except for the current command and slot.
for (int slot = 0; slot < mSimCount; slot++) {
@@ -1903,18 +1891,15 @@ public class StkAppService extends Service implements Runnable {
}
}
}
- unregisterProcessObserver();
+ unregisterHomeVisibilityObserver();
}
- private synchronized void unregisterProcessObserver() {
- if (mProcessObserver != null) {
- try {
- ActivityManagerNative.getDefault().unregisterProcessObserver(mProcessObserver);
- CatLog.d(LOG_TAG, "Stopped to observe the foreground activity");
- mProcessObserver = null;
- } catch (RemoteException e) {
- CatLog.d(LOG_TAG, "Failed to unregister the process observer");
- }
+ private synchronized void unregisterHomeVisibilityObserver() {
+ if (mHomeVisibilityObserver != null) {
+ ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
+ am.unregisterHomeVisibilityObserver(mHomeVisibilityObserver);
+ CatLog.d(LOG_TAG, "Stopped to observe the foreground activity");
+ mHomeVisibilityObserver = null;
}
}
@@ -2021,7 +2006,7 @@ public class StkAppService extends Service implements Runnable {
case IDLE_SCREEN_AVAILABLE_EVENT:
// The process observer can be unregistered
// as the idle screen has already been available.
- unregisterProcessObserver();
+ unregisterHomeVisibilityObserver();
break;
default:
break;
@@ -2144,7 +2129,7 @@ public class StkAppService extends Service implements Runnable {
}
private void cancelIdleText(int slotId) {
- unregisterProcessObserver(AppInterface.CommandType.SET_UP_IDLE_MODE_TEXT, slotId);
+ unregisterHomeVisibilityObserver(AppInterface.CommandType.SET_UP_IDLE_MODE_TEXT, slotId);
mNotificationManager.cancel(getNotificationId(slotId));
mStkContext[slotId].mIdleModeTextCmd = null;
mStkContext[slotId].mIdleModeTextVisible = false;