OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.webapps; | 5 package org.chromium.chrome.browser.webapps; |
6 | 6 |
7 import android.content.ActivityNotFoundException; | 7 import android.content.ActivityNotFoundException; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.net.Uri; | 10 import android.net.Uri; |
(...skipping 19 matching lines...) Expand all Loading... |
30 * @return True if the install was started. A "true" return value does not g
uarantee that the | 30 * @return True if the install was started. A "true" return value does not g
uarantee that the |
31 * install succeeds. | 31 * install succeeds. |
32 */ | 32 */ |
33 @CalledByNative | 33 @CalledByNative |
34 static boolean installAsyncFromNative(String filePath, String packageName) { | 34 static boolean installAsyncFromNative(String filePath, String packageName) { |
35 if (!installingFromUnknownSourcesAllowed()) { | 35 if (!installingFromUnknownSourcesAllowed()) { |
36 Log.e(TAG, | 36 Log.e(TAG, |
37 "WebAPK install failed because installation from unknown sou
rces is disabled."); | 37 "WebAPK install failed because installation from unknown sou
rces is disabled."); |
38 return false; | 38 return false; |
39 } | 39 } |
40 if (!new File(filePath).exists()) { | |
41 return false; | |
42 } | |
43 Intent intent = new Intent(Intent.ACTION_VIEW); | 40 Intent intent = new Intent(Intent.ACTION_VIEW); |
44 Uri fileUri = Uri.fromFile(new File(filePath)); | 41 Uri fileUri = Uri.fromFile(new File(filePath)); |
45 intent.setDataAndType(fileUri, "application/vnd.android.package-archive"
); | 42 intent.setDataAndType(fileUri, "application/vnd.android.package-archive"
); |
46 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 43 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
47 try { | 44 try { |
48 ContextUtils.getApplicationContext().startActivity(intent); | 45 ContextUtils.getApplicationContext().startActivity(intent); |
49 } catch (ActivityNotFoundException e) { | 46 } catch (ActivityNotFoundException e) { |
50 return false; | 47 return false; |
51 } | 48 } |
52 return true; | 49 return true; |
53 } | 50 } |
54 | 51 |
55 /** | 52 /** |
56 * Returns whether the user has enabled installing apps from sources other t
han the Google Play | 53 * Returns whether the user has enabled installing apps from sources other t
han the Google Play |
57 * Store. | 54 * Store. |
58 */ | 55 */ |
59 private static boolean installingFromUnknownSourcesAllowed() { | 56 private static boolean installingFromUnknownSourcesAllowed() { |
60 Context context = ContextUtils.getApplicationContext(); | 57 Context context = ContextUtils.getApplicationContext(); |
61 try { | 58 try { |
62 return Settings.Secure.getInt( | 59 return Settings.Secure.getInt( |
63 context.getContentResolver(), Settings.Secure.INSTALL
_NON_MARKET_APPS) | 60 context.getContentResolver(), Settings.Secure.INSTALL
_NON_MARKET_APPS) |
64 == 1; | 61 == 1; |
65 } catch (Settings.SettingNotFoundException e) { | 62 } catch (Settings.SettingNotFoundException e) { |
66 return false; | 63 return false; |
67 } | 64 } |
68 } | 65 } |
69 } | 66 } |
OLD | NEW |