• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

packages/apps/Settings


Commit MetaInfo

Revisiónc4329b1e96e3f5dfe9b3bb9e2c2a64d6e238216f (tree)
Tiempo2020-02-21 13:36:01
AutorChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

Use DownloadManager to get native bridge libraries

Cambiar Resumen

Diferencia incremental

--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -3228,6 +3228,12 @@
32283228 android:value="true" />
32293229 </activity>
32303230
3231+ <receiver android:name=".DownloadCompleteReceiver">
3232+ <intent-filter>
3233+ <action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
3234+ </intent-filter>
3235+ </receiver>
3236+
32313237 <activity
32323238 android:name=".Settings$AccountDashboardActivity"
32333239 android:label="@string/account_dashboard_title"
--- /dev/null
+++ b/src/com/android/settings/DownloadCompleteReceiver.java
@@ -0,0 +1,36 @@
1+/*
2+ * Copyright (C) 2020 The Android-x86 Open Source Project
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+package com.android.settings;
18+
19+import android.app.DownloadManager;
20+import android.content.BroadcastReceiver;
21+import android.content.Context;
22+import android.content.Intent;
23+
24+import static com.android.settings.system.AndroidX86DashboardFragment.onDownloadComplete;
25+
26+public final class DownloadCompleteReceiver extends BroadcastReceiver {
27+ private static final String TAG = "Dl-Receiver";
28+
29+ @Override
30+ public void onReceive(Context context, Intent intent) {
31+ if (intent.getAction().equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
32+ DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
33+ onDownloadComplete(dm);
34+ }
35+ }
36+}
--- a/src/com/android/settings/system/AndroidX86DashboardFragment.java
+++ b/src/com/android/settings/system/AndroidX86DashboardFragment.java
@@ -1,5 +1,5 @@
11 /*
2- * Copyright (C) 2018 The Android-x86 Open Source Project
2+ * Copyright (C) 2018-2020 The Android-x86 Open Source Project
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -16,34 +16,50 @@
1616
1717 package com.android.settings.system;
1818
19+import android.app.DownloadManager;
20+import android.app.DownloadManager.Query;
21+import android.app.DownloadManager.Request;
22+import android.content.Context;
23+import android.database.Cursor;
24+import android.net.Uri;
1925 import android.os.Bundle;
26+import android.os.Environment;
2027 import android.os.SystemProperties;
2128 import android.support.v7.preference.Preference;
2229 import android.support.v14.preference.SwitchPreference;
30+import android.util.Log;
2331 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
2432 import com.android.settings.R;
2533 import com.android.settings.SettingsPreferenceFragment;
34+import dalvik.system.VMRuntime;
35+import java.io.File;
2636
2737 public class AndroidX86DashboardFragment extends SettingsPreferenceFragment {
2838
39+ private DownloadManager mDownloadManager;
2940 private SwitchPreference mNativeBridgePreference;
3041 private SwitchPreference mHwInfoPreference;
3142 private SwitchPreference mAppsUsagePreference;
3243
44+ private static final String TAG = "Dl-NB";
3345 private static final String KEY_TOGGLE_NB = "toggle_nb";
3446 private static final String PROPERTY_NATIVEBRIDGE = "persist.sys.nativebridge";
3547 private static final String KEY_TOGGLE_HW_INFO = "toggle_hw_info";
3648 private static final String PROPERTY_HW_INFO = "persist.sys.hw_statistics";
3749 private static final String KEY_TOGGLE_APPS_USAGE = "toggle_apps_usage";
3850 private static final String PROPERTY_APPS_USAGE = "persist.sys.apps_statistics";
51+ private static final String NB_LIBRARIES = "Native bridge libraries ";
52+ private static long sDownloadId = -1;
53+ private static int sDownloadStatus = -1;
3954
4055 @Override
4156 public void onCreate(Bundle icicle) {
4257 super.onCreate(icicle);
4358
59+ mDownloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
4460 addPreferencesFromResource(R.xml.android_x86_options);
4561 mNativeBridgePreference = (SwitchPreference) findPreference(KEY_TOGGLE_NB);
46- mNativeBridgePreference.setChecked(SystemProperties.getBoolean(PROPERTY_NATIVEBRIDGE, false));
62+ checkNativeBridgeStatus();
4763 mHwInfoPreference = (SwitchPreference) findPreference(KEY_TOGGLE_HW_INFO);
4864 mHwInfoPreference.setChecked(SystemProperties.getBoolean(PROPERTY_HW_INFO, true));
4965 mAppsUsagePreference = (SwitchPreference) findPreference(KEY_TOGGLE_APPS_USAGE);
@@ -53,7 +69,7 @@ public class AndroidX86DashboardFragment extends SettingsPreferenceFragment {
5369 @Override
5470 public boolean onPreferenceTreeClick(Preference preference) {
5571 if (preference == mNativeBridgePreference) {
56- SystemProperties.set(PROPERTY_NATIVEBRIDGE, mNativeBridgePreference.isChecked() ? "1" : "0");
72+ setNativeBridge(mNativeBridgePreference.isChecked());
5773 } else if (preference == mHwInfoPreference) {
5874 SystemProperties.set(PROPERTY_HW_INFO, Boolean.toString(mHwInfoPreference.isChecked()));
5975 } else if (preference == mAppsUsagePreference) {
@@ -66,4 +82,104 @@ public class AndroidX86DashboardFragment extends SettingsPreferenceFragment {
6682 public int getMetricsCategory() {
6783 return MetricsEvent.APPLICATION;
6884 }
85+
86+ private boolean isNativeBridgeAvailable() {
87+ File file = new File("/system/lib/libhoudini.so");
88+ return file.length() > 0;
89+ }
90+
91+ private void checkNativeBridgeStatus() {
92+ boolean nb = SystemProperties.getBoolean(PROPERTY_NATIVEBRIDGE, false);
93+ if (!isNativeBridgeAvailable()) {
94+ queryDownloading(mDownloadManager);
95+ if (sDownloadStatus == DownloadManager.STATUS_RUNNING) {
96+ nb = true;
97+ } else if (nb) {
98+ downloadNativeBridge();
99+ }
100+ }
101+ mNativeBridgePreference.setChecked(nb);
102+ }
103+
104+ private void setNativeBridge(boolean enabled) {
105+ Log.d(TAG, "setNativeBridge: " + enabled);
106+ if (isNativeBridgeAvailable()) {
107+ setNativeBridgeProperty(enabled);
108+ } else if (enabled) {
109+ downloadNativeBridge();
110+ } else if (sDownloadId != -1) {
111+ mDownloadManager.remove(sDownloadId);
112+ sDownloadId = -1;
113+ }
114+ }
115+
116+ private void downloadNativeBridge() {
117+ String url, file;
118+ if (VMRuntime.getRuntime().is64Bit()) {
119+ url = "https://t.cn/EJrmYMH";
120+ file = "houdini9_y.sfs";
121+ } else {
122+ url = "https://t.cn/EJrmzZv";
123+ file = "houdini9_x.sfs";
124+ }
125+
126+ File path = Environment.getExternalStoragePublicDirectory("arm");
127+ path.mkdirs();
128+ File nb = new File(path, file);
129+ if (nb.exists()) {
130+ if (sDownloadId != -1) {
131+ switch (sDownloadStatus) {
132+ case DownloadManager.STATUS_SUCCESSFUL:
133+ setNativeBridgeProperty(true); // fall through
134+ case DownloadManager.STATUS_RUNNING:
135+ return;
136+ default:
137+ break;
138+ }
139+ }
140+ nb.delete();
141+ }
142+ mDownloadManager.remove(sDownloadId);
143+
144+ Request request = new Request(Uri.parse(url)).
145+ setDestinationUri(Uri.fromFile(nb)).
146+ setTitle(NB_LIBRARIES + file.substring(7, 10));
147+
148+ sDownloadId = mDownloadManager.enqueue(request);
149+ Log.i(TAG, "downloading " + url);
150+ }
151+
152+ private static void queryDownloading(DownloadManager dm) {
153+ Query query = new Query().setFilterByString(NB_LIBRARIES);
154+ Cursor c = null;
155+ try {
156+ c = dm.query(query);
157+ if (c.moveToFirst()) {
158+ sDownloadId = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_ID));
159+ sDownloadStatus = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
160+ Log.i(TAG, "id: " + sDownloadId + " status: " + sDownloadStatus);
161+ }
162+ } catch (Exception e) {
163+ Log.w(TAG, "Exception: " + e);
164+ } finally {
165+ if (c != null) {
166+ c.close();
167+ }
168+ }
169+ }
170+
171+ private static void setNativeBridgeProperty(boolean enabled) {
172+ SystemProperties.set(PROPERTY_NATIVEBRIDGE, enabled ? "1" : "0");
173+ }
174+
175+ public static void onDownloadComplete(DownloadManager dm) {
176+ queryDownloading(dm);
177+ boolean success = sDownloadStatus == DownloadManager.STATUS_SUCCESSFUL;
178+ if (success) {
179+ Log.i(TAG, "download success, native bridge enabled");
180+ } else {
181+ Log.w(TAG, "download failed: " + sDownloadStatus);
182+ }
183+ setNativeBridgeProperty(success);
184+ }
69185 }