Skip to content

Commit

Permalink
Merge pull request #141 from inoshperera/master
Browse files Browse the repository at this point in the history
  • Loading branch information
inoshperera authored Jan 29, 2018
2 parents bff9060 + bad4173 commit 3079e72
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 6 deletions.
1 change: 1 addition & 0 deletions client/client/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="org.wso2.iot.system.service.permission.ACCESS" />
<uses-permission android:name="org.wso2.iot.agent.permission.ACCESS" />
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,20 @@ public void onClick(View v) {
missingPermissions.add(android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
}

NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
// This is to handle permission obtaining for Android N devices where operations such
// as mute that can cause a device to go into "do not disturb" will need additional
// permission. Added here as well to support already enrolled devices to optain the
// permission without reenrolling.
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M && !notificationManager
.isNotificationPolicyAccessGranted()) {
CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
getResources().getString(R.string.dialog_do_not_distrub_title),
getResources().getString(R.string.dialog_do_not_distrub_message),
getResources().getString(R.string.ok), doNotDisturbClickListener);
}

if (missingPermissions.isEmpty()) {
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel(Constants.PERMISSION_MISSING, Constants.PERMISSION_MISSING_NOTIFICATION_ID);
Expand Down Expand Up @@ -271,6 +285,17 @@ public void onClick(View v) {
}
}

private DialogInterface.OnClickListener doNotDisturbClickListener = new DialogInterface
.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(
android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
startActivityForResult(intent, Constants.DO_NOT_DISTURB_REQUEST_CODE);
dialog.dismiss();
}
};

@Override
protected void onDestroy(){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public class AuthenticationActivity extends AppCompatActivity implements APIAcce
private DeviceInfo deviceInfo;
private static final String TAG = AuthenticationActivity.class.getSimpleName();
private static final int ACTIVATION_REQUEST = 47;
private static final int PERMISSION_REQUEST = 48;
private static final String[] SUBSCRIBED_API = new String[]{"android"};
private Tenant currentTenant;
private DevicePolicyManager devicePolicyManager;
Expand Down Expand Up @@ -613,7 +614,10 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
startDeviceAdminPrompt();
}
}
}
if (requestCode == Constants.DO_NOT_DISTURB_REQUEST_CODE) {
getConfigurationsFromServer();
}
}


@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
Expand Down Expand Up @@ -752,7 +756,7 @@ private void checkManifestPermissions() {
android.Manifest.permission.ACCESS_COARSE_LOCATION,
android.Manifest.permission.ACCESS_FINE_LOCATION,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE},
110);
PERMISSION_REQUEST);
} else {
getConfigurationsFromServer();
}
Expand All @@ -772,10 +776,34 @@ private void checkManifestPermissions() {
public void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions,
@NonNull int[] grantResults) {
if(requestCode == 110){
getConfigurationsFromServer();
}
}
if (requestCode == PERMISSION_REQUEST) {
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M && !notificationManager
.isNotificationPolicyAccessGranted()) {
CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
getResources().getString(R.string.dialog_do_not_distrub_title),
getResources().getString(R.string.dialog_do_not_distrub_message),
getResources().getString(R.string.ok), doNotDisturbClickListener);
} else {
getConfigurationsFromServer();
}
}
}

private DialogInterface.OnClickListener doNotDisturbClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// This is to handle permission obtaining for Android N devices where operations such
// as mute that can cause a device to go into "do not disturb" will need additional
// permission.
Intent intent = new Intent(
android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
startActivityForResult(intent, Constants.DO_NOT_DISTURB_REQUEST_CODE);
}
};




/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public class Constants {
public static final int APP_LIST_REQUEST_CODE = 313;
public static final int DYNAMIC_CLIENT_UNREGISTER_REQUEST_CODE = 314;
public static final int SCEP_REQUEST_CODE = 300;
public static final int DO_NOT_DISTURB_REQUEST_CODE = 315;
/**
* Tag used on log messages.
*/
Expand Down
4 changes: 4 additions & 0 deletions client/client/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@
<string name="dialog_system_app_required">Please install the WSO2 System App to continue enrollment as a COPE user.</string>
<string name="dialog_tenants_not_available">You do not have any associated organizations. Please contact your administrator</string>
<string name="dialog_select_tenant">Select an Organization to register your device with.</string>
<string name="dialog_do_not_distrub_title">Permission for do not disturb mode change</string>
<string name="dialog_do_not_distrub_message">Some operations such as mute, requires agent
application to be able to control do not disturb mode, please enable it from
the next screen. After ticking, please press back and return to the agent</string>

<!-- REGISTRATION -->
<string name="register_button_text">Register</string>
Expand Down

0 comments on commit 3079e72

Please sign in to comment.