Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.widget.Toast;
import androidx.core.content.FileProvider;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -178,7 +179,15 @@ public void updateOnline(String url) {
}

public void installLocally(Uri uri) {
mHandler.obtainMessage(MSG_INSTALL_LOCALLY, uri).sendToTarget();
Message message = mHandler.obtainMessage(MSG_INSTALL_LOCALLY, uri);
message.arg1 = 0;
mHandler.sendMessage(message);
}

public void installLocallyFromAdb(String rpkPath) {
Message message = mHandler.obtainMessage(MSG_INSTALL_LOCALLY, rpkPath);
message.arg1 = 1;
mHandler.sendMessage(message);
}

public void startDebugging(String pkg, String server, String target) {
Expand Down Expand Up @@ -297,6 +306,35 @@ private void onInstallLocally(Uri uri) {
}
}

private void onInstallLocallyFromAdb(String rpkPath) {
Log.e(TAG, "rpkPath: " + rpkPath);
if (TextUtils.isEmpty(rpkPath)) {
return;
}
File tempFile = createTempFile();
if (tempFile != null) {
Log.e(TAG, "tempFile: " + tempFile.getAbsolutePath());
InputStream in = null;
try {
in = new FileInputStream(rpkPath);
boolean success = FileUtils.saveToFile(in, tempFile);
if (success) {
mRetryRpkFile = tempFile;
installPackageInPlatform(tempFile);
return;
}
} catch (FileNotFoundException e) {
Log.e(TAG, "Fail to save local file", e);
onError(ERROR_CODE_FAIL_TO_SAVE_LOCAL_FILE);
} finally {
FileUtils.closeQuietly(in);
}
tempFile.delete();
} else {
onError(ERROR_CODE_FAIL_TO_CREATE_TEMP_FILE);
}
}

private boolean isOtherFileExceptRpk(Uri uri) {
if (mActivityRf != null) {
final Activity activity = mActivityRf.get();
Expand Down Expand Up @@ -653,9 +691,14 @@ public void handleMessage(Message msg) {
getServer();
break;
}

Uri uri = (Uri) msg.obj;
onInstallLocally(uri);
boolean isFromAdb = msg.arg1 == 1;
if (isFromAdb) {
String rpkPath = (String) msg.obj;
onInstallLocallyFromAdb(rpkPath);
} else {
Uri uri = (Uri) msg.obj;
onInstallLocally(uri);
}
break;
}
case MSG_START_DEBUGGING: {
Expand Down Expand Up @@ -734,4 +777,4 @@ public void handleMessage(Message msg) {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public abstract class DebugFragment extends Fragment implements AdapterView.OnIt
private static final String EXTRA_IDE_PATH = "path";
private static final String EXTRA_IDE_DEBUG = "debug";
private static final String EXTRA_IDE_IS_ADJUSTED = "isAdjustedIde";
private static final String EXTRA_RPK_ADDRESS = "rpk_address";
private static final String SCAN_PARAMS_TARGET = "target";
private static final String SCAN_TARGET_VALUE_SKELETON = "skeleton";
protected boolean mIsIdeDebug;
Expand Down Expand Up @@ -208,8 +209,17 @@ protected void handleIDERequest(Intent intent) {
String path = intent.getStringExtra(EXTRA_IDE_PATH);
mIsIdeDebug = intent.getBooleanExtra(EXTRA_IDE_DEBUG, false);
boolean isAdjustedIde = intent.getBooleanExtra(EXTRA_IDE_IS_ADJUSTED, false);
String rpk_address = intent.getStringExtra(EXTRA_RPK_ADDRESS);

if (!TextUtils.isEmpty(path)) {
if (!TextUtils.isEmpty(rpk_address)) {
getActivity().setIntent(null);
Log.i(TAG, "handleIDERequest() -- rpk_address:" + rpk_address);
if (!rpk_address.toLowerCase().startsWith("http")
&& !rpk_address.toLowerCase().startsWith("https")) {
Log.e(TAG, "handleIDERequest() -- installLocallyFromAdb");
AppDebugManager.getInstance(getActivity()).installLocallyFromAdb(rpk_address);
}
} else if (!TextUtils.isEmpty(path)) {
getActivity().setIntent(null);
PreferenceUtils.setServer(getActivity(), path);
PreferenceUtils.setUniversalScan(getActivity(), false);
Expand Down Expand Up @@ -689,4 +699,4 @@ public void run() {
});
}
}
}
}