mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-30 21:55:31 +00:00
Bug 1241887 - (Part 2) UpdateService: Show notification if permission is missing. r=nalexander
--HG-- extra : commitid : AFcj5zu2agN extra : rebase_source : ce27690c57aacdc385162ef6cd1419160eabf45b
This commit is contained in:
parent
7240d8c49a
commit
31f9c12564
@ -11,10 +11,12 @@ import org.mozilla.gecko.R;
|
||||
|
||||
import org.mozilla.apache.commons.codec.binary.Hex;
|
||||
|
||||
import org.mozilla.gecko.permissions.Permissions;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.IntentService;
|
||||
import android.app.Notification;
|
||||
@ -30,7 +32,9 @@ import android.net.Uri;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.net.wifi.WifiManager.WifiLock;
|
||||
import android.os.Environment;
|
||||
import android.provider.Settings;
|
||||
import android.support.v4.app.NotificationManagerCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.net.ConnectivityManagerCompat;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.app.NotificationCompat.Builder;
|
||||
@ -180,7 +184,7 @@ public class UpdateService extends IntentService {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHandleIntent (Intent intent) {
|
||||
protected void onHandleIntent (final Intent intent) {
|
||||
if (UpdateServiceHelper.ACTION_REGISTER_FOR_UPDATES.equals(intent.getAction())) {
|
||||
AutoDownloadPolicy policy = AutoDownloadPolicy.get(
|
||||
intent.getIntExtra(UpdateServiceHelper.EXTRA_AUTODOWNLOAD_NAME,
|
||||
@ -259,7 +263,7 @@ public class UpdateService extends IntentService {
|
||||
manager.set(AlarmManager.RTC_WAKEUP, lastAttempt.getTimeInMillis(), pending);
|
||||
}
|
||||
|
||||
private void startUpdate(int flags) {
|
||||
private void startUpdate(final int flags) {
|
||||
setLastAttemptDate();
|
||||
|
||||
NetworkInfo netInfo = mConnectivityManager.getActiveNetworkInfo();
|
||||
@ -272,7 +276,7 @@ public class UpdateService extends IntentService {
|
||||
|
||||
registerForUpdates(false);
|
||||
|
||||
UpdateInfo info = findUpdate(hasFlag(flags, UpdateServiceHelper.FLAG_REINSTALL));
|
||||
final UpdateInfo info = findUpdate(hasFlag(flags, UpdateServiceHelper.FLAG_REINSTALL));
|
||||
boolean haveUpdate = (info != null);
|
||||
|
||||
if (!haveUpdate) {
|
||||
@ -283,6 +287,23 @@ public class UpdateService extends IntentService {
|
||||
|
||||
Log.i(LOGTAG, "update available, buildID = " + info.buildID);
|
||||
|
||||
Permissions.from(this)
|
||||
.withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
.doNotPrompt()
|
||||
.andFallback(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
showPermissionNotification();
|
||||
sendCheckUpdateResult(CheckUpdateResult.NOT_AVAILABLE);
|
||||
}})
|
||||
.run(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startDownload(info, flags);
|
||||
}});
|
||||
}
|
||||
|
||||
private void startDownload(UpdateInfo info, int flags) {
|
||||
AutoDownloadPolicy policy = getAutoDownloadPolicy();
|
||||
|
||||
// We only start a download automatically if one of following criteria are met:
|
||||
@ -293,8 +314,8 @@ public class UpdateService extends IntentService {
|
||||
// is OK with large data transfers occurring)
|
||||
//
|
||||
boolean shouldStartDownload = hasFlag(flags, UpdateServiceHelper.FLAG_FORCE_DOWNLOAD) ||
|
||||
policy == AutoDownloadPolicy.ENABLED ||
|
||||
(policy == AutoDownloadPolicy.WIFI && !ConnectivityManagerCompat.isActiveNetworkMetered(mConnectivityManager));
|
||||
policy == AutoDownloadPolicy.ENABLED ||
|
||||
(policy == AutoDownloadPolicy.WIFI && !ConnectivityManagerCompat.isActiveNetworkMetered(mConnectivityManager));
|
||||
|
||||
if (!shouldStartDownload) {
|
||||
Log.i(LOGTAG, "not initiating automatic update download due to policy " + policy.toString());
|
||||
@ -679,6 +700,29 @@ public class UpdateService extends IntentService {
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void showPermissionNotification() {
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
|
||||
Uri.fromParts("package", getPackageName(), null));
|
||||
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
|
||||
|
||||
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle()
|
||||
.bigText(getString(R.string.updater_permission_text));
|
||||
|
||||
Notification notification = new NotificationCompat.Builder(this)
|
||||
.setContentTitle(getString(R.string.updater_permission_title))
|
||||
.setContentText(getString(R.string.updater_permission_text))
|
||||
.setStyle(bigTextStyle)
|
||||
.setAutoCancel(true)
|
||||
.setSmallIcon(R.drawable.ic_status_logo)
|
||||
.setColor(ContextCompat.getColor(this, R.color.rejection_red))
|
||||
.setContentIntent(pendingIntent)
|
||||
.build();
|
||||
|
||||
NotificationManagerCompat.from(this)
|
||||
.notify(R.id.updateServicePermissionNotification, notification);
|
||||
}
|
||||
|
||||
private String getLastBuildID() {
|
||||
return mPrefs.getString(KEY_LAST_BUILDID, null);
|
||||
}
|
||||
|
@ -664,7 +664,14 @@ just addresses the organization to follow, e.g. "This site is run by " -->
|
||||
<!ENTITY updater_apply_title2 "Update available for &brandShortName;">
|
||||
<!ENTITY updater_apply_select2 "Touch to update">
|
||||
|
||||
<!-- Guest mode -->
|
||||
<!-- Localization note (updater_permission_text): This text is shown in a notification and as a snackbar
|
||||
if the app requires a runtime permission to download updates. Currently, the updater only sees
|
||||
remotely advertised updates in the Nightly and Aurora channels. -->
|
||||
<!ENTITY updater_permission_text "To download files and updates, allow &brandShortName; permission to access storage.">
|
||||
<!-- LOCALIZATION NOTE (updater_permission_allow): This action is shown in a snackbar along with updater_permission_text. -->
|
||||
<!ENTITY updater_permission_allow "Allow">
|
||||
|
||||
<!-- Guest mode -->
|
||||
<!ENTITY new_guest_session "New Guest Session">
|
||||
<!ENTITY exit_guest_session "Exit Guest Session">
|
||||
<!ENTITY guest_session_dialog_continue "Continue">
|
||||
|
@ -16,5 +16,6 @@
|
||||
<item type="id" name="pref_header_general"/>
|
||||
<item type="id" name="pref_header_privacy"/>
|
||||
<item type="id" name="pref_header_search"/>
|
||||
<item type="id" name="updateServicePermissionNotification" />
|
||||
|
||||
</resources>
|
||||
|
@ -539,6 +539,9 @@
|
||||
<string name="updater_apply_title">&updater_apply_title2;</string>
|
||||
<string name="updater_apply_select">&updater_apply_select2;</string>
|
||||
|
||||
<string name="updater_permission_title">&brandShortName;</string>
|
||||
<string name="updater_permission_text">&updater_permission_text;</string>
|
||||
|
||||
<!-- Awesomescreen screen -->
|
||||
<string name="suggestions_prompt">&suggestions_prompt3;</string>
|
||||
<string name="search_bar_item_desc">&search_bar_item_desc;</string>
|
||||
|
Loading…
Reference in New Issue
Block a user