am 212bd428: Merge "Make granting default SMS and Phone permissions robust" into mnc-dev

* commit '212bd4280de4d94efcd91e11c5169b6cf239d85a':
  Make granting default SMS and Phone permissions robust
This commit is contained in:
Svetoslav
2015-07-02 21:47:49 +00:00
committed by Android Git Automerger
2 changed files with 136 additions and 38 deletions

View File

@@ -287,20 +287,6 @@ final class DefaultPermissionGrantPolicy {
grantRuntimePermissionsLPw(setupPackage, SETTINGS_PERMISSIONS, userId); grantRuntimePermissionsLPw(setupPackage, SETTINGS_PERMISSIONS, userId);
} }
// Dialer
if (dialerAppPackageNames != null) {
for (String dialerAppPackageName : dialerAppPackageNames) {
PackageParser.Package dialerPackage = getPackageLPr(dialerAppPackageName);
if (dialerPackage != null
&& doesPackageSupportRuntimePermissions(dialerPackage)) {
grantRuntimePermissionsLPw(dialerPackage, PHONE_PERMISSIONS, userId);
grantRuntimePermissionsLPw(dialerPackage, CONTACTS_PERMISSIONS, userId);
grantRuntimePermissionsLPw(dialerPackage, SMS_PERMISSIONS, userId);
grantRuntimePermissionsLPw(dialerPackage, MICROPHONE_PERMISSIONS, userId);
}
}
}
// Camera // Camera
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
PackageParser.Package cameraPackage = getDefaultSystemHandlerActivityPackageLPr( PackageParser.Package cameraPackage = getDefaultSystemHandlerActivityPackageLPr(
@@ -342,15 +328,37 @@ final class DefaultPermissionGrantPolicy {
grantRuntimePermissionsLPw(storagePackage, STORAGE_PERMISSIONS, userId); grantRuntimePermissionsLPw(storagePackage, STORAGE_PERMISSIONS, userId);
} }
// Dialer
if (dialerAppPackageNames == null) {
Intent dialerIntent = new Intent(Intent.ACTION_DIAL);
PackageParser.Package dialerPackage = getDefaultSystemHandlerActivityPackageLPr(
dialerIntent, userId);
if (dialerPackage != null) {
grantDefaultPermissionsToDefaultSystemDialerAppLPr(dialerPackage, userId);
}
} else {
for (String dialerAppPackageName : dialerAppPackageNames) {
PackageParser.Package dialerPackage = getSystemPackageLPr(dialerAppPackageName);
if (dialerPackage != null) {
grantDefaultPermissionsToDefaultSystemDialerAppLPr(dialerPackage, userId);
}
}
}
// SMS // SMS
if (smsAppPackageNames != null) { if (smsAppPackageNames == null) {
Intent smsIntent = new Intent(Intent.ACTION_MAIN);
smsIntent.addCategory(Intent.CATEGORY_APP_MESSAGING);
PackageParser.Package smsPackage = getDefaultSystemHandlerActivityPackageLPr(
smsIntent, userId);
if (smsPackage != null) {
grantDefaultPermissionsToDefaultSystemSmsAppLPr(smsPackage, userId);
}
} else {
for (String smsPackageName : smsAppPackageNames) { for (String smsPackageName : smsAppPackageNames) {
PackageParser.Package smsPackage = getPackageLPr(smsPackageName); PackageParser.Package smsPackage = getSystemPackageLPr(smsPackageName);
if (smsPackage != null if (smsPackage != null) {
&& doesPackageSupportRuntimePermissions(smsPackage)) { grantDefaultPermissionsToDefaultSystemSmsAppLPr(smsPackage, userId);
grantRuntimePermissionsLPw(smsPackage, PHONE_PERMISSIONS, userId);
grantRuntimePermissionsLPw(smsPackage, CONTACTS_PERMISSIONS, userId);
grantRuntimePermissionsLPw(smsPackage, SMS_PERMISSIONS, userId);
} }
} }
} }
@@ -379,8 +387,8 @@ final class DefaultPermissionGrantPolicy {
} }
// Calendar provider sync adapters // Calendar provider sync adapters
List<PackageParser.Package> calendarSyncAdapters = List<PackageParser.Package> calendarSyncAdapters = getHeadlessSyncAdapterPackagesLPr(
getHeadlessSyncAdapterPackagesLPr(calendarSyncAdapterPackages, calendarSyncAdapterPackages,
userId); userId);
final int calendarSyncAdapterCount = calendarSyncAdapters.size(); final int calendarSyncAdapterCount = calendarSyncAdapters.size();
for (int i = 0; i < calendarSyncAdapterCount; i++) { for (int i = 0; i < calendarSyncAdapterCount; i++) {
@@ -403,8 +411,8 @@ final class DefaultPermissionGrantPolicy {
} }
// Contacts provider sync adapters // Contacts provider sync adapters
List<PackageParser.Package> contactsSyncAdapters = List<PackageParser.Package> contactsSyncAdapters = getHeadlessSyncAdapterPackagesLPr(
getHeadlessSyncAdapterPackagesLPr(contactsSyncAdapterPackages, contactsSyncAdapterPackages,
userId); userId);
final int contactsSyncAdapterCount = contactsSyncAdapters.size(); final int contactsSyncAdapterCount = contactsSyncAdapters.size();
for (int i = 0; i < contactsSyncAdapterCount; i++) { for (int i = 0; i < contactsSyncAdapterCount; i++) {
@@ -541,6 +549,27 @@ final class DefaultPermissionGrantPolicy {
} }
} }
private void grantDefaultPermissionsToDefaultSystemDialerAppLPr(
PackageParser.Package dialerPackage, int userId) {
if (doesPackageSupportRuntimePermissions(dialerPackage)) {
grantRuntimePermissionsLPw(dialerPackage, PHONE_PERMISSIONS, userId);
grantRuntimePermissionsLPw(dialerPackage, CONTACTS_PERMISSIONS, userId);
grantRuntimePermissionsLPw(dialerPackage, SMS_PERMISSIONS, userId);
grantRuntimePermissionsLPw(dialerPackage, MICROPHONE_PERMISSIONS, userId);
}
}
private void grantDefaultPermissionsToDefaultSystemSmsAppLPr(
PackageParser.Package smsPackage, int userId) {
if (doesPackageSupportRuntimePermissions(smsPackage)) {
grantRuntimePermissionsLPw(smsPackage, PHONE_PERMISSIONS, userId);
grantRuntimePermissionsLPw(smsPackage, CONTACTS_PERMISSIONS, userId);
grantRuntimePermissionsLPw(smsPackage, SMS_PERMISSIONS, userId);
}
}
public void grantDefaultPermissionsToDefaultSmsAppLPr(String packageName, int userId) { public void grantDefaultPermissionsToDefaultSmsAppLPr(String packageName, int userId) {
Log.i(TAG, "Granting permissions to default sms app for user:" + userId); Log.i(TAG, "Granting permissions to default sms app for user:" + userId);
if (packageName == null) { if (packageName == null) {

View File

@@ -31,8 +31,11 @@ import android.os.ServiceManager;
import android.os.UserHandle; import android.os.UserHandle;
import android.provider.Settings; import android.provider.Settings;
import android.telecom.DefaultDialerManager; import android.telecom.DefaultDialerManager;
import android.util.IntArray;
import android.util.Slog; import android.util.Slog;
import android.util.SparseBooleanArray;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.telephony.SmsApplication; import com.android.internal.telephony.SmsApplication;
import com.android.server.LocalServices; import com.android.server.LocalServices;
import com.android.server.SystemService; import com.android.server.SystemService;
@@ -59,6 +62,41 @@ public class TelecomLoaderService extends SystemService {
}, 0); }, 0);
SmsApplication.getDefaultMmsApplication(mContext, false); SmsApplication.getDefaultMmsApplication(mContext, false);
ServiceManager.addService(Context.TELECOM_SERVICE, service); ServiceManager.addService(Context.TELECOM_SERVICE, service);
synchronized (mLock) {
if (mDefaultSmsAppRequests != null || mDefaultDialerAppRequests != null) {
final PackageManagerInternal packageManagerInternal = LocalServices
.getService(PackageManagerInternal.class);
if (mDefaultSmsAppRequests != null) {
ComponentName smsComponent = SmsApplication.getDefaultSmsApplication(
mContext, true);
if (smsComponent != null) {
final int requestCount = mDefaultSmsAppRequests.size();
for (int i = requestCount - 1; i >= 0; i--) {
final int userid = mDefaultSmsAppRequests.get(i);
mDefaultSmsAppRequests.remove(i);
packageManagerInternal.grantDefaultPermissionsToDefaultSmsApp(
smsComponent.getPackageName(), userid);
}
}
}
if (mDefaultDialerAppRequests != null) {
String packageName = DefaultDialerManager.getDefaultDialerApplication(
mContext);
if (packageName != null) {
final int requestCount = mDefaultDialerAppRequests.size();
for (int i = requestCount - 1; i >= 0; i--) {
final int userId = mDefaultDialerAppRequests.get(i);
mDefaultDialerAppRequests.remove(i);
packageManagerInternal.grantDefaultPermissionsToDefaultDialerApp(
packageName, userId);
}
}
}
}
}
} catch (RemoteException e) { } catch (RemoteException e) {
Slog.w(TAG, "Failed linking to death."); Slog.w(TAG, "Failed linking to death.");
} }
@@ -76,7 +114,17 @@ public class TelecomLoaderService extends SystemService {
private static final String SERVICE_ACTION = "com.android.ITelecomService"; private static final String SERVICE_ACTION = "com.android.ITelecomService";
private final Object mLock = new Object();
@GuardedBy("mLock")
private IntArray mDefaultSmsAppRequests;
@GuardedBy("mLock")
private IntArray mDefaultDialerAppRequests;
private final Context mContext; private final Context mContext;
@GuardedBy("mLock")
private TelecomServiceConnection mServiceConnection; private TelecomServiceConnection mServiceConnection;
public TelecomLoaderService(Context context) { public TelecomLoaderService(Context context) {
@@ -98,24 +146,27 @@ public class TelecomLoaderService extends SystemService {
} }
private void connectToTelecom() { private void connectToTelecom() {
if (mServiceConnection != null) { synchronized (mLock) {
// TODO: Is unbinding worth doing or wait for system to rebind? if (mServiceConnection != null) {
mContext.unbindService(mServiceConnection); // TODO: Is unbinding worth doing or wait for system to rebind?
mServiceConnection = null; mContext.unbindService(mServiceConnection);
} mServiceConnection = null;
}
TelecomServiceConnection serviceConnection = new TelecomServiceConnection(); TelecomServiceConnection serviceConnection = new TelecomServiceConnection();
Intent intent = new Intent(SERVICE_ACTION); Intent intent = new Intent(SERVICE_ACTION);
intent.setComponent(SERVICE_COMPONENT); intent.setComponent(SERVICE_COMPONENT);
int flags = Context.BIND_IMPORTANT | Context.BIND_FOREGROUND_SERVICE int flags = Context.BIND_IMPORTANT | Context.BIND_FOREGROUND_SERVICE
| Context.BIND_AUTO_CREATE; | Context.BIND_AUTO_CREATE;
// Bind to Telecom and register the service // Bind to Telecom and register the service
if (mContext.bindServiceAsUser(intent, serviceConnection, flags, UserHandle.OWNER)) { if (mContext.bindServiceAsUser(intent, serviceConnection, flags, UserHandle.OWNER)) {
mServiceConnection = serviceConnection; mServiceConnection = serviceConnection;
}
} }
} }
private void registerDefaultAppProviders() { private void registerDefaultAppProviders() {
final PackageManagerInternal packageManagerInternal = LocalServices.getService( final PackageManagerInternal packageManagerInternal = LocalServices.getService(
PackageManagerInternal.class); PackageManagerInternal.class);
@@ -125,6 +176,15 @@ public class TelecomLoaderService extends SystemService {
new PackageManagerInternal.PackagesProvider() { new PackageManagerInternal.PackagesProvider() {
@Override @Override
public String[] getPackages(int userId) { public String[] getPackages(int userId) {
synchronized (mLock) {
if (mServiceConnection == null) {
if (mDefaultSmsAppRequests == null) {
mDefaultSmsAppRequests = new IntArray();
}
mDefaultSmsAppRequests.add(userId);
return null;
}
}
ComponentName smsComponent = SmsApplication.getDefaultSmsApplication( ComponentName smsComponent = SmsApplication.getDefaultSmsApplication(
mContext, true); mContext, true);
if (smsComponent != null) { if (smsComponent != null) {
@@ -139,6 +199,15 @@ public class TelecomLoaderService extends SystemService {
new PackageManagerInternal.PackagesProvider() { new PackageManagerInternal.PackagesProvider() {
@Override @Override
public String[] getPackages(int userId) { public String[] getPackages(int userId) {
synchronized (mLock) {
if (mServiceConnection == null) {
if (mDefaultDialerAppRequests == null) {
mDefaultDialerAppRequests = new IntArray();
}
mDefaultDialerAppRequests.add(userId);
return null;
}
}
String packageName = DefaultDialerManager.getDefaultDialerApplication(mContext); String packageName = DefaultDialerManager.getDefaultDialerApplication(mContext);
if (packageName != null) { if (packageName != null) {
return new String[]{packageName}; return new String[]{packageName};