Add package name check for the calling app
Bug: 198661951 Test: make RunSettingsRoboTests ROBOTEST_FILTER=AddAppNetworksActivityTest Change-Id: I68a543a5c9a5b74db30780f6a6d9f9bc9c6eec08
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user