summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiangyu/Malcolm Chen <refuhoo@google.com>2020-01-21 20:58:46 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-01-21 20:58:46 +0000
commit35b9789c65da2c9f05ecd7f82d39340657645e4e (patch)
tree68bbf026de0a5f944201159a56692e242407f5a9
parent158ab9943a4299fa8a6fe0b52557933a5ea4587c (diff)
parent549e21a596d1a5533ebe908fe547965dde5d64d6 (diff)
downloadStk-35b9789c65da2c9f05ecd7f82d39340657645e4e.tar.gz
Merge "Use new @System API in ActivityManager to monitor screen being idle."
-rw-r--r--src/com/android/stk/StkAppService.java80
1 files changed, 32 insertions, 48 deletions
diff --git a/src/com/android/stk/StkAppService.java b/src/com/android/stk/StkAppService.java
index 4aac130..2bd8af0 100644
--- a/src/com/android/stk/StkAppService.java
+++ b/src/com/android/stk/StkAppService.java
@@ -23,9 +23,8 @@ import static com.android.internal.telephony.cat.CatCmdMessage.SetupEventListCon
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
-import android.app.ActivityManagerNative;
import android.app.AlertDialog;
-import android.app.IProcessObserver;
+import android.app.HomeVisibilityObserver;
import android.app.KeyguardManager;
import android.app.Notification;
import android.app.NotificationChannel;
@@ -72,8 +71,6 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
-import androidx.localbroadcastmanager.content.LocalBroadcastManager;
-
import com.android.internal.telephony.GsmAlphabet;
import com.android.internal.telephony.PhoneConfigurationManager;
import com.android.internal.telephony.PhoneConstants;
@@ -95,6 +92,8 @@ import com.android.internal.telephony.uicc.IccRefreshResponse;
import java.util.LinkedList;
import java.util.List;
+import androidx.localbroadcastmanager.content.LocalBroadcastManager;
+
/**
* SIM toolkit application level service. Interacts with Telephopny messages,
* application's launch and user input from STK UI elements.
@@ -172,7 +171,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;
@@ -405,7 +404,7 @@ public class StkAppService extends Service implements Runnable {
public void onDestroy() {
CatLog.d(LOG_TAG, "onDestroy()");
unregisterUserActivityReceiver();
- unregisterProcessObserver();
+ unregisterHomeVisibilityObserver();
unregisterLocaleChangeReceiver();
unregisterHomeKeyEventReceiver();
sInstance = null;
@@ -1163,7 +1162,7 @@ public class StkAppService extends Service implements Runnable {
CatLog.d(LOG_TAG, "set up idle mode");
launchIdleText(slotId);
} else {
- registerProcessObserver();
+ registerHomeVisibilityObserver();
}
}
break;
@@ -1778,7 +1777,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();
@@ -1798,7 +1797,7 @@ public class StkAppService extends Service implements Runnable {
registerUserActivityReceiver();
break;
case IDLE_SCREEN_AVAILABLE_EVENT:
- registerProcessObserver();
+ registerHomeVisibilityObserver();
break;
case LANGUAGE_SELECTION_EVENT:
registerLocaleChangeReceiver();
@@ -1843,37 +1842,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++) {
@@ -1896,18 +1883,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;
}
}
@@ -2014,7 +1998,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;
@@ -2137,7 +2121,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;