Skip to content

Commit

Permalink
Fix issues in setting OTA policy pre-P or without freeze
Browse files Browse the repository at this point in the history
Bug: 78446129
Test: Set policy without freeze periods; set policy on an Oreo device
Change-Id: I0d98f91b827f2aeb18ce2646c56d9d6b1b41014c
  • Loading branch information
Rubin Xu committed Apr 23, 2018
1 parent c1ad4b0 commit 1495460
Showing 1 changed file with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,21 +281,22 @@ private boolean setSystemUpdatePolicy() {
default:
newPolicy = null;
}
if (BuildCompat.isAtLeastP() && newPolicy != null && mFreezePeriods.size() != 0) {
List<FreezePeriod> periods = new ArrayList<>(mFreezePeriods.size());
for (Period p : mFreezePeriods) {
periods.add(p.toFreezePeriod());
}
try {

try {
if (BuildCompat.isAtLeastP() && newPolicy != null && mFreezePeriods.size() != 0) {
final List<FreezePeriod> periods = new ArrayList<>(mFreezePeriods.size());
for (Period p : mFreezePeriods) {
periods.add(p.toFreezePeriod());
}
newPolicy.setFreezePeriods(periods);
mDpm.setSystemUpdatePolicy(DeviceAdminReceiver.getComponentName(getActivity()),
newPolicy);
Toast.makeText(getContext(), "Policy set successfully", Toast.LENGTH_LONG).show();
return true;
} catch (IllegalArgumentException e) {
Toast.makeText(getContext(), "Failed to set system update policy: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
mDpm.setSystemUpdatePolicy(DeviceAdminReceiver.getComponentName(getActivity()),
newPolicy);
Toast.makeText(getContext(), "Policy set successfully", Toast.LENGTH_LONG).show();
return true;
} catch (IllegalArgumentException e) {
Toast.makeText(getContext(), "Failed to set system update policy: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
return false;
}
Expand Down

0 comments on commit 1495460

Please sign in to comment.