Skip to content

Instantly share code, notes, and snippets.

@yesidlazaro
Created October 21, 2016 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save yesidlazaro/57d5c4e3afe3598794dfd9b4f96484aa to your computer and use it in GitHub Desktop.
Save yesidlazaro/57d5c4e3afe3598794dfd9b4f96484aa to your computer and use it in GitHub Desktop.
Fix OpenGApps permissions on CyanogenMod 13

Fix OpenGApps permissions on CyanogenMod 13

Updating to CyanogenMod 13 with OpenGApps is problematic and results in issues including repeated warnings such as

Unfortunately, setup wizard has stopped working

Or

Unfortunately, Google Play Services has stopped working

Or the Setup Wizard asking you to set up your device but not allowing you to proceed.


The problem originates from Google Core apps not having required permissions and thus crashing or otherwise not working properly. This fix grants the required permissions to Google Apps and was originally written by @TheCrazyLex and consists of a ROM patch. I converted it to a bash script that utilizes pm grant to achieve the same result without the requirement of patching your ROM.

Usage

Place the script on your device and execute it after CyanogenMod booted, you may delete the file afterwards.

adb push fix_open_gapps_permissions.sh /sdcard/
adb shell 'bash /sdcard/fix_open_gapps_permissions.sh'
adb shell 'rm /sdcard/fix_open_gapps_permissions.sh'

If you don't have access to ADB, you can download the file onto your device or place it on the sdcard. To execute it, enable Developer Options → Local terminal and use the Terminal app.

#!/system/bin/env bash
# taken from https://github.com/TeamExodus/frameworks_base/commit/9c36be651e83fb039a262682839bd920b033007a
# converted to bash script by @jomo
PHONE_PERMISSIONS="READ_PHONE_STATE CALL_PHONE READ_CALL_LOG WRITE_CALL_LOG ADD_VOICEMAIL USE_SIP PROCESS_OUTGOING_CALLS"
CONTACTS_PERMISSIONS="READ_CONTACTS WRITE_CONTACTS GET_ACCOUNTS"
LOCATION_PERMISSIONS="ACCESS_FINE_LOCATION ACCESS_COARSE_LOCATION"
CALENDAR_PERMISSIONS="READ_CALENDAR WRITE_CALENDAR"
SMS_PERMISSIONS="SEND_SMS RECEIVE_SMS READ_SMS RECEIVE_WAP_PUSH RECEIVE_MMS READ_CELL_BROADCASTS"
MICROPHONE_PERMISSIONS="RECORD_AUDIO"
CAMERA_PERMISSIONS="CAMERA"
SENSORS_PERMISSIONS="BODY_SENSORS"
STORAGE_PERMISSIONS="READ_EXTERNAL_STORAGE WRITE_EXTERNAL_STORAGE"
grantPerms() {
for perm in $2; do
echo ">" pm grant "$1" android.permission."$perm"
pm grant "$1" android.permission."$perm" 2>/dev/null
done
}
# Google Account
googleaccountPackage="com.google.android.gsf.login"
grantPerms "$googleaccountPackage" "$CONTACTS_PERMISSIONS"
grantPerms "$googleaccountPackage" "$PHONE_PERMISSIONS"
# Google App
googleappPackage="com.google.android.googlequicksearchbox"
grantPerms "$googleappPackage" "$CALENDAR_PERMISSIONS"
grantPerms "$googleappPackage" "$CAMERA_PERMISSIONS"
grantPerms "$googleappPackage" "$CONTACTS_PERMISSIONS"
grantPerms "$googleappPackage" "$LOCATION_PERMISSIONS"
grantPerms "$googleappPackage" "$MICROPHONE_PERMISSIONS"
grantPerms "$googleappPackage" "$PHONE_PERMISSIONS"
grantPerms "$googleappPackage" "$SMS_PERMISSIONS"
grantPerms "$googleappPackage" "$STORAGE_PERMISSIONS"
# Google Play Services
gmscorePackage="com.google.android.gms"
grantPerms "$gmscorePackage" "$SENSORS_PERMISSIONS"
grantPerms "$gmscorePackage" "$CALENDAR_PERMISSIONS"
grantPerms "$gmscorePackage" "$CAMERA_PERMISSIONS"
grantPerms "$gmscorePackage" "$CONTACTS_PERMISSIONS"
grantPerms "$gmscorePackage" "$LOCATION_PERMISSIONS"
grantPerms "$gmscorePackage" "$MICROPHONE_PERMISSIONS"
grantPerms "$gmscorePackage" "$PHONE_PERMISSIONS"
grantPerms "$gmscorePackage" "$SMS_PERMISSIONS"
grantPerms "$gmscorePackage" "$STORAGE_PERMISSIONS"
# Google Connectivity Services
gcsPackage="com.google.android.apps.gcs"
grantPerms "$gcsPackage" "$CONTACTS_PERMISSIONS"
grantPerms "$gcsPackage" "$LOCATION_PERMISSIONS"
# Google Contacts Sync
googlecontactssyncPackage="com.google.android.syncadapters.contacts"
grantPerms "$googlecontactssyncPackage" "$CONTACTS_PERMISSIONS"
# Google Backup Transport
googlebackuptransportPackage="com.google.android.backuptransport"
grantPerms "$googlebackuptransportPackage" "$CONTACTS_PERMISSIONS"
# Google Play Framework
gsfcorePackage="com.google.android.gsf"
grantPerms "$gsfcorePackage" "$CONTACTS_PERMISSIONS"
grantPerms "$gsfcorePackage" "$PHONE_PERMISSIONS"
# Google Setup Wizard
setupwizardPackage="com.google.android.setupwizard"
grantPerms "$setupwizardPackage" "$CONTACTS_PERMISSIONS"
grantPerms "$setupwizardPackage" "$PHONE_PERMISSIONS"
# Google Play Store
vendingPackage="com.android.vending"
grantPerms "$vendingPackage" "$CONTACTS_PERMISSIONS"
grantPerms "$vendingPackage" "$PHONE_PERMISSIONS"
grantPerms "$vendingPackage" "$LOCATION_PERMISSIONS"
grantPerms "$vendingPackage" "$SMS_PERMISSIONS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment