Access mock location is no longer a runtime permission - settings

The access mock location is no longer a runtime permission. It is a
signature protected one that apps cannot get but the fact they request
it means they want to inject location into the system. Now the user
gets to choose the current mock location app in developer options from
the apps that request the mock location permission. The access to mock
location is no longer guarded by the permisson but from a new app op
which is off by default and the settiings UI sets it to enabled only
for the currently selected mock location app.

bug:21078873

Change-Id: I6555179ecf0cc37d9bb857e9dfb3b04c091ea612
This commit is contained in:
Svet Ganov
2015-05-13 10:39:35 -07:00
committed by Svetoslav
parent 0c3d8f1c0f
commit 02e65a181a
4 changed files with 156 additions and 24 deletions

View File

@@ -22,6 +22,8 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import com.android.settings.applications.AppViewHolder;
import android.app.ListActivity;
@@ -40,10 +42,20 @@ import android.widget.ListView;
public class AppPicker extends ListActivity {
private AppListAdapter mAdapter;
public static final String EXTRA_REQUESTIING_PERMISSION
= "com.android.settings.extra.REQUESTIING_PERMISSION";
public static final String EXTRA_DEBUGGABLE = "com.android.settings.extra.DEBUGGABLE";
private String mPermissionName;
private boolean mDebuggableOnly;
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
mPermissionName = getIntent().getStringExtra(EXTRA_REQUESTIING_PERMISSION);
mDebuggableOnly = getIntent().getBooleanExtra(EXTRA_DEBUGGABLE, false);
mAdapter = new AppListAdapter(this);
if (mAdapter.getCount() <= 0) {
finish();
@@ -89,13 +101,41 @@ public class AppPicker extends ListActivity {
if (ai.uid == Process.SYSTEM_UID) {
continue;
}
// On a user build, we only allow debugging of apps that
// are marked as debuggable. Otherwise (for platform development)
// we allow all apps.
if ((ai.flags&ApplicationInfo.FLAG_DEBUGGABLE) == 0
&& "user".equals(Build.TYPE)) {
continue;
// Filter out apps that are not debuggable if required.
if (mDebuggableOnly) {
// On a user build, we only allow debugging of apps that
// are marked as debuggable. Otherwise (for platform development)
// we allow all apps.
if ((ai.flags&ApplicationInfo.FLAG_DEBUGGABLE) == 0
&& "user".equals(Build.TYPE)) {
continue;
}
}
// Filter out apps that do not request the permission if required.
if (mPermissionName != null) {
boolean requestsPermission = false;
try {
PackageInfo pi = getPackageManager().getPackageInfo(ai.packageName,
PackageManager.GET_PERMISSIONS);
if (pi.requestedPermissions == null) {
continue;
}
for (String requestedPermission : pi.requestedPermissions) {
if (requestedPermission.equals(mPermissionName)) {
requestsPermission = true;
break;
}
}
if (!requestsPermission) {
continue;
}
} catch (PackageManager.NameNotFoundException e) {
continue;
}
}
MyApplicationInfo info = new MyApplicationInfo();
info.info = ai;
info.label = info.info.loadLabel(getPackageManager()).toString();