diff options
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/stk/StkAppService.java | 80 |
1 files changed, 32 insertions, 48 deletions
diff --git a/src/com/android/stk/StkAppService.java b/src/com/android/stk/StkAppService.java index d60f9a4..dc66de3 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.ITelephony; import com.android.internal.telephony.PhoneConfigurationManager; @@ -96,6 +93,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. @@ -173,7 +172,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; @@ -406,7 +405,7 @@ public class StkAppService extends Service implements Runnable { public void onDestroy() { CatLog.d(LOG_TAG, "onDestroy()"); unregisterUserActivityReceiver(); - unregisterProcessObserver(); + unregisterHomeVisibilityObserver(); unregisterLocaleChangeReceiver(); unregisterHomeKeyEventReceiver(); sInstance = null; @@ -1164,7 +1163,7 @@ public class StkAppService extends Service implements Runnable { CatLog.d(LOG_TAG, "set up idle mode"); launchIdleText(slotId); } else { - registerProcessObserver(); + registerHomeVisibilityObserver(); } } break; @@ -1779,7 +1778,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(); @@ -1799,7 +1798,7 @@ public class StkAppService extends Service implements Runnable { registerUserActivityReceiver(); break; case IDLE_SCREEN_AVAILABLE_EVENT: - registerProcessObserver(); + registerHomeVisibilityObserver(); break; case LANGUAGE_SELECTION_EVENT: registerLocaleChangeReceiver(); @@ -1844,37 +1843,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++) { @@ -1897,18 +1884,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; } } @@ -2015,7 +1999,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; @@ -2138,7 +2122,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; |