Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.omaha; | 5 package org.chromium.chrome.browser.omaha; |
| 6 | 6 |
| 7 import android.annotation.TargetApi; | |
| 7 import android.content.ActivityNotFoundException; | 8 import android.content.ActivityNotFoundException; |
| 8 import android.content.Context; | 9 import android.content.Context; |
| 9 import android.content.Intent; | 10 import android.content.Intent; |
| 10 import android.graphics.Bitmap; | 11 import android.graphics.Bitmap; |
| 11 import android.graphics.BitmapFactory; | 12 import android.graphics.BitmapFactory; |
| 12 import android.graphics.Canvas; | 13 import android.graphics.Canvas; |
| 13 import android.graphics.Paint; | 14 import android.graphics.Paint; |
| 14 import android.graphics.PorterDuff; | 15 import android.graphics.PorterDuff; |
| 15 import android.graphics.PorterDuffXfermode; | 16 import android.graphics.PorterDuffXfermode; |
| 16 import android.net.Uri; | 17 import android.net.Uri; |
| 17 import android.os.AsyncTask; | 18 import android.os.AsyncTask; |
| 19 import android.os.Build; | |
| 20 import android.os.Environment; | |
| 21 import android.os.StatFs; | |
| 18 import android.text.TextUtils; | 22 import android.text.TextUtils; |
| 19 | 23 |
| 20 import org.chromium.base.CommandLine; | 24 import org.chromium.base.CommandLine; |
| 21 import org.chromium.base.Log; | 25 import org.chromium.base.Log; |
| 22 import org.chromium.base.ThreadUtils; | 26 import org.chromium.base.ThreadUtils; |
| 23 import org.chromium.base.metrics.RecordHistogram; | 27 import org.chromium.base.metrics.RecordHistogram; |
| 24 import org.chromium.chrome.R; | 28 import org.chromium.chrome.R; |
| 25 import org.chromium.chrome.browser.ChromeActivity; | 29 import org.chromium.chrome.browser.ChromeActivity; |
| 26 import org.chromium.chrome.browser.ChromeSwitches; | 30 import org.chromium.chrome.browser.ChromeSwitches; |
| 27 import org.chromium.chrome.browser.appmenu.AppMenu; | 31 import org.chromium.chrome.browser.appmenu.AppMenu; |
| 28 import org.chromium.chrome.browser.preferences.PrefServiceBridge; | 32 import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
| 29 import org.chromium.components.variations.VariationsAssociatedData; | 33 import org.chromium.components.variations.VariationsAssociatedData; |
| 30 import org.chromium.ui.base.LocalizationUtils; | 34 import org.chromium.ui.base.LocalizationUtils; |
| 31 | 35 |
| 36 import java.io.File; | |
| 37 | |
| 32 /** | 38 /** |
| 33 * Contains logic for whether the update menu item should be shown, whether the update toolbar badge | 39 * Contains logic for whether the update menu item should be shown, whether the update toolbar badge |
| 34 * should be shown, and UMA logging for the update menu item. | 40 * should be shown, and UMA logging for the update menu item. |
| 35 */ | 41 */ |
| 36 public class UpdateMenuItemHelper { | 42 public class UpdateMenuItemHelper { |
| 37 private static final String TAG = "UpdateMenuItemHelper"; | 43 private static final String TAG = "UpdateMenuItemHelper"; |
| 38 | 44 |
| 39 // VariationsAssociatedData configs | 45 // VariationsAssociatedData configs |
| 40 private static final String FIELD_TRIAL_NAME = "UpdateMenuItem"; | 46 private static final String FIELD_TRIAL_NAME = "UpdateMenuItem"; |
| 41 private static final String ENABLED_VALUE = "true"; | 47 private static final String ENABLED_VALUE = "true"; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 } | 111 } |
| 106 | 112 |
| 107 mAlreadyCheckedForUpdates = true; | 113 mAlreadyCheckedForUpdates = true; |
| 108 | 114 |
| 109 new AsyncTask<Void, Void, Void>() { | 115 new AsyncTask<Void, Void, Void>() { |
| 110 @Override | 116 @Override |
| 111 protected Void doInBackground(Void... params) { | 117 protected Void doInBackground(Void... params) { |
| 112 if (OmahaClient.isNewerVersionAvailable(activity)) { | 118 if (OmahaClient.isNewerVersionAvailable(activity)) { |
| 113 mUpdateUrl = OmahaClient.getMarketURL(activity); | 119 mUpdateUrl = OmahaClient.getMarketURL(activity); |
| 114 mUpdateAvailable = true; | 120 mUpdateAvailable = true; |
| 121 recordInternalStorageSize(); | |
|
Yaron
2016/01/04 14:37:24
nit: you were already in an asynctask so it's not
Theresa
2016/01/04 21:02:29
Great point. I'll fix that in a follow up CL.
| |
| 115 } else { | 122 } else { |
| 116 mUpdateAvailable = false; | 123 mUpdateAvailable = false; |
| 117 } | 124 } |
| 118 return null; | 125 return null; |
| 119 } | 126 } |
| 120 | 127 |
| 121 @Override | 128 @Override |
| 122 protected void onPostExecute(Void result) { | 129 protected void onPostExecute(Void result) { |
| 123 if (activity.isActivityDestroyed()) return; | 130 if (activity.isActivityDestroyed()) return; |
| 124 activity.onCheckForUpdate(mUpdateAvailable); | 131 activity.onCheckForUpdate(mUpdateAvailable); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 * @param paramName The name of the parameter (or command-line switch) to ge t a value for. | 316 * @param paramName The name of the parameter (or command-line switch) to ge t a value for. |
| 310 * @return The command-line flag value if present, or the param is value if present. | 317 * @return The command-line flag value if present, or the param is value if present. |
| 311 */ | 318 */ |
| 312 private static String getStringParamValue(String paramName) { | 319 private static String getStringParamValue(String paramName) { |
| 313 String value = CommandLine.getInstance().getSwitchValue(paramName); | 320 String value = CommandLine.getInstance().getSwitchValue(paramName); |
| 314 if (TextUtils.isEmpty(value)) { | 321 if (TextUtils.isEmpty(value)) { |
| 315 value = VariationsAssociatedData.getVariationParamValue(FIELD_TRIAL_ NAME, paramName); | 322 value = VariationsAssociatedData.getVariationParamValue(FIELD_TRIAL_ NAME, paramName); |
| 316 } | 323 } |
| 317 return value; | 324 return value; |
| 318 } | 325 } |
| 326 | |
| 327 private void recordInternalStorageSize() { | |
| 328 new AsyncTask<Void, Void, Void>() { | |
| 329 @Override | |
| 330 protected Void doInBackground(Void... params) { | |
| 331 File path = Environment.getDataDirectory(); | |
| 332 StatFs statFs = new StatFs(path.getAbsolutePath()); | |
| 333 int size; | |
| 334 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { | |
| 335 size = getSize(statFs); | |
| 336 } else { | |
| 337 size = getSizeUpdatedApi(statFs); | |
| 338 } | |
| 339 RecordHistogram.recordLinearCountHistogram( | |
| 340 "GoogleUpdate.InfoBar.InternalStorageSizeAvailable", siz e, 1, 200, 100); | |
| 341 return null; | |
| 342 } | |
| 343 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | |
| 344 } | |
| 345 | |
| 346 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) | |
| 347 private static int getSizeUpdatedApi(StatFs statFs) { | |
| 348 return (int) statFs.getAvailableBytes() / (1024 * 1024); | |
| 349 } | |
| 350 | |
| 351 @SuppressWarnings("deprecation") | |
| 352 private static int getSize(StatFs statFs) { | |
| 353 int blockSize = statFs.getBlockSize(); | |
| 354 int availableBlocks = statFs.getAvailableBlocks(); | |
| 355 int size = (blockSize * availableBlocks) / (1024 * 1024); | |
| 356 return size; | |
| 357 } | |
| 319 } | 358 } |
| OLD | NEW |