Merge "Add package name check for the calling app" into sc-v2-dev am: 12b7fd54ec

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/16062219

Change-Id: I248616eaed0c9c3d19612d702b97e851f1847e2a
This commit is contained in:
TreeHugger Robot
2021-11-04 03:07:48 +00:00
committed by Automerger Merge Worker
2 changed files with 90 additions and 14 deletions

View File

@@ -16,9 +16,14 @@
package com.android.settings.wifi.addappnetworks;
import android.app.ActivityManager;
import android.app.IActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.os.RemoteException;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
@@ -48,12 +53,17 @@ public class AddAppNetworksActivity extends FragmentActivity {
@VisibleForTesting
final Bundle mBundle = new Bundle();
@VisibleForTesting
IActivityManager mActivityManager = ActivityManager.getService();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_panel);
showAddNetworksFragment();
if (!showAddNetworksFragment()) {
finish();
return;
}
getLifecycle().addObserver(new HideNonSystemOverlayMixin(this));
// Move the window to the bottom of screen, and make it take up the entire screen width.
@@ -67,13 +77,22 @@ public class AddAppNetworksActivity extends FragmentActivity {
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
showAddNetworksFragment();
if (!showAddNetworksFragment()) {
finish();
return;
}
}
@VisibleForTesting
void showAddNetworksFragment() {
protected boolean showAddNetworksFragment() {
String packageName = getCallingAppPackageName();
if (TextUtils.isEmpty(packageName)) {
Log.d(TAG, "Package name is null");
return false;
}
// TODO: Check the new intent status.
mBundle.putString(KEY_CALLING_PACKAGE_NAME, getCallingPackage());
mBundle.putString(KEY_CALLING_PACKAGE_NAME, packageName);
mBundle.putParcelableArrayList(Settings.EXTRA_WIFI_NETWORK_LIST,
getIntent().getParcelableArrayListExtra(Settings.EXTRA_WIFI_NETWORK_LIST));
@@ -86,5 +105,19 @@ public class AddAppNetworksActivity extends FragmentActivity {
} else {
((AddAppNetworksFragment) fragment).createContent(mBundle);
}
return true;
}
@VisibleForTesting
protected String getCallingAppPackageName() {
String packageName;
try {
packageName = mActivityManager.getLaunchedFromPackage(getActivityToken());
} catch (RemoteException e) {
Log.e(TAG, "Can not get the package from activity manager");
return null;
}
return packageName;
}
}