-
Notifications
You must be signed in to change notification settings - Fork 498
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Android 6.0 runtime permissions
Reorder and comment permissions Runtime permission WIP Show permission error message Simplify Calendar permissions Handle service notification request account manager permission Remove debug Default to light SDK 10 fixes Bump version
- Loading branch information
Showing
35 changed files
with
602 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
app/src/main/java/com/zegoggles/smssync/activity/AppPermission.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.zegoggles.smssync.activity; | ||
|
||
import android.Manifest; | ||
import android.content.pm.PackageManager; | ||
import android.content.res.Resources; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.text.TextUtils; | ||
import com.zegoggles.smssync.R; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static android.content.pm.PackageManager.PERMISSION_DENIED; | ||
|
||
public enum AppPermission { | ||
READ_SMS(Manifest.permission.READ_SMS, R.string.permission_read_sms), | ||
READ_CALL_LOG(Manifest.permission.READ_CALL_LOG, R.string.permission_read_call_log), | ||
READ_CONTACTS(Manifest.permission.READ_CONTACTS, R.string.permission_read_contacts), | ||
UNKNOWN(null, R.string.permission_unknown); | ||
|
||
final int descriptionResource; | ||
final @Nullable String androidPermission; | ||
|
||
AppPermission(String androidPermission, int descriptionResource) { | ||
this.androidPermission = androidPermission; | ||
this.descriptionResource = descriptionResource; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "AppPermission{" + androidPermission + '}'; | ||
} | ||
|
||
public static AppPermission from(@NonNull String androidPermission) { | ||
for (AppPermission appPermission : AppPermission.values()) { | ||
if (androidPermission.equals(appPermission.androidPermission)) { | ||
return appPermission; | ||
} | ||
} | ||
return UNKNOWN; | ||
} | ||
|
||
public static List<AppPermission> from(@NonNull String[] androidPermissions) { | ||
List<AppPermission> appPermissions = new ArrayList<AppPermission>(); | ||
for (String permission : androidPermissions) { | ||
appPermissions.add(from(permission)); | ||
} | ||
return appPermissions; | ||
} | ||
|
||
public static List<AppPermission> from(@NonNull String[] androidPermissions, @NonNull int[] grantResults) { | ||
List<AppPermission> appPermissions = new ArrayList<AppPermission>(); | ||
for (int i=0; i<androidPermissions.length; i++) { | ||
if (grantResults[i] == PERMISSION_DENIED) { | ||
appPermissions.add(from(androidPermissions[i])); | ||
} | ||
} | ||
return appPermissions; | ||
} | ||
|
||
public static boolean allGranted(@NonNull int[] grantResults) { | ||
for (int result : grantResults) { | ||
if (result == PackageManager.PERMISSION_DENIED) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
public static String formatMissingPermissionDetails(Resources resources, String[] androidPermissions) { | ||
return formatMissingPermissionDetails(resources, from(androidPermissions)); | ||
} | ||
|
||
public static String formatMissingPermissionDetails(Resources resources, List<AppPermission> appPermissions) { | ||
List<String> permissions = new ArrayList<String>(); | ||
for (AppPermission permission : appPermissions) { | ||
permissions.add(resources.getString(permission.descriptionResource)); | ||
} | ||
return resources.getQuantityString(R.plurals.status_permission_problem_details, | ||
permissions.size(), | ||
TextUtils.join(", ", permissions)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.