Fix UsbResolverActivity SuperNotCalledException (pt2)

Instead of calling the normal path, this change creates
a path to call Activity#onCreate directly and avoid
initializing state when the activity is about to self
finish()

Bug: 201719995
Test: adb shell am start -n
      com.android.systemui/com.android.systemui.usb.UsbResolverActivity
Change-Id: I40ee792e341b828a3e288b1fc713f6df13728b4a
This commit is contained in:
Mark Renouf
2021-10-04 11:28:25 -04:00
parent c1512c20e5
commit 46abffb3de
2 changed files with 11 additions and 4 deletions

View File

@@ -314,6 +314,15 @@ public class ResolverActivity extends Activity implements
return intent;
}
/**
* Call {@link Activity#onCreate} without initializing anything further. This should
* only be used when the activity is about to be immediately finished to avoid wasting
* initializing steps and leaking resources.
*/
protected void super_onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// Use a specialized prompt when we're handling the 'Home' app startActivity()

View File

@@ -63,8 +63,7 @@ public class UsbResolverActivity extends ResolverActivity {
Intent intent = getIntent();
Parcelable targetParcelable = intent.getParcelableExtra(Intent.EXTRA_INTENT);
if (!(targetParcelable instanceof Intent)) {
super.onCreate(savedInstanceState);
onStop(); // unregister receiver registered in onCreate (PackageMonitor)
super_onCreate(savedInstanceState);
Log.w("UsbResolverActivity", "Target is not an intent: " + targetParcelable);
finish();
return;
@@ -97,8 +96,7 @@ public class UsbResolverActivity extends ResolverActivity {
} else {
mAccessory = (UsbAccessory)target.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);
if (mAccessory == null) {
super.onCreate(savedInstanceState);
onStop(); // unregister receiver registered in onCreate (PackageMonitor)
super_onCreate(savedInstanceState);
Log.e(TAG, "no device or accessory");
finish();
return;