Fix NPE in OverviewComponentObserver constructor while accessing activityInfo.

Bug: 132461400
Test: Manual tests
Change-Id: Icee3730454db8129e597714c147c2cbaddc70987
(cherry picked from commit 219208a0f5)
This commit is contained in:
Rajeev Kumar 2019-06-17 11:35:03 -07:00 committed by Sunny Goyal
parent 700dc99d9b
commit 8ca7205c24
1 changed files with 45 additions and 10 deletions

View File

@ -19,15 +19,21 @@ import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_SYS
import android.annotation.TargetApi;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Region;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Process;
import android.os.RemoteException;
import android.util.Log;
import android.view.MotionEvent;
import com.android.launcher3.Utilities;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.systemui.shared.recents.IOverviewProxy;
import com.android.systemui.shared.recents.ISystemUiProxy;
@ -37,7 +43,16 @@ import com.android.systemui.shared.recents.ISystemUiProxy;
@TargetApi(Build.VERSION_CODES.O)
public class TouchInteractionService extends Service {
private static final String TAG = "TouchInteractionService";
private static final String TAG = "GoTouchInteractionService";
private boolean mIsUserUnlocked;
private BroadcastReceiver mUserUnlockedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_USER_UNLOCKED.equals(intent.getAction())) {
initWhenUserUnlocked();
}
}
};
private final IBinder mMyBinder = new IOverviewProxy.Stub() {
@ -53,17 +68,21 @@ public class TouchInteractionService extends Service {
@Override
public void onOverviewToggle() {
if (mIsUserUnlocked) {
mOverviewCommandHelper.onOverviewToggle();
}
}
@Override
public void onOverviewShown(boolean triggeredFromAltTab) {
if (mIsUserUnlocked) {
mOverviewCommandHelper.onOverviewShown(triggeredFromAltTab);
}
}
@Override
public void onOverviewHidden(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) {
if (triggeredFromAltTab && !triggeredFromHomeKey) {
if (mIsUserUnlocked && triggeredFromAltTab && !triggeredFromHomeKey) {
// onOverviewShownFromAltTab hides the overview and ends at the target app
mOverviewCommandHelper.onOverviewHidden();
}
@ -71,8 +90,10 @@ public class TouchInteractionService extends Service {
@Override
public void onTip(int actionType, int viewType) {
if (mIsUserUnlocked) {
mOverviewCommandHelper.onTip(actionType, viewType);
}
}
@Override
public void onAssistantAvailable(boolean available) {
@ -123,17 +144,31 @@ public class TouchInteractionService extends Service {
@Override
public void onCreate() {
super.onCreate();
mRecentsModel = RecentsModel.INSTANCE.get(this);
mOverviewComponentObserver = new OverviewComponentObserver(this);
mOverviewCommandHelper = new OverviewCommandHelper(this,
mOverviewComponentObserver);
if (UserManagerCompat.getInstance(this).isUserUnlocked(Process.myUserHandle())) {
initWhenUserUnlocked();
} else {
mIsUserUnlocked = false;
registerReceiver(mUserUnlockedReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED));
}
sConnected = true;
}
private void initWhenUserUnlocked() {
mRecentsModel = RecentsModel.INSTANCE.get(this);
mOverviewComponentObserver = new OverviewComponentObserver(this);
mOverviewCommandHelper = new OverviewCommandHelper(this,
mOverviewComponentObserver);
mIsUserUnlocked = true;
Utilities.unregisterReceiverSafely(this, mUserUnlockedReceiver);
}
@Override
public void onDestroy() {
if (mIsUserUnlocked) {
mOverviewComponentObserver.onDestroy();
}
Utilities.unregisterReceiverSafely(this, mUserUnlockedReceiver);
sConnected = false;
super.onDestroy();
}