Skip to content

Commit

Permalink
Merge pull request #175 from charithag/master
Browse files Browse the repository at this point in the history
 Code formatting PR #165 and enabling multi-dex
  • Loading branch information
charithag authored Apr 17, 2018
2 parents 8e39477 + 7af9143 commit 09f1c4b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
1 change: 1 addition & 0 deletions client/client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ dependencies {
compile 'commons-net:commons-net:3.3'
compile "org.java-websocket:Java-WebSocket:1.3.0"
compile "org.apache.commons:commons-lang3:3.6"
compile 'com.android.support:multidex:1.0.1'
}

apply plugin: 'com.google.gms.google-services'
Expand Down
1 change: 0 additions & 1 deletion client/client/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permisssion.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MANAGE_MEDIA_PROJECTION" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
package org.wso2.iot.agent;

import android.app.AlarmManager;
import android.app.Application;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.multidex.MultiDexApplication;
import android.util.Log;

import com.splunk.mint.Mint;
Expand All @@ -31,7 +31,7 @@
import org.wso2.iot.agent.utils.CommonUtils;
import org.wso2.iot.agent.utils.Constants;

public class AgentApplication extends Application {
public class AgentApplication extends MultiDexApplication {

// Configs
private int requestCode = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package org.wso2.iot.agent.api;

import android.annotation.TargetApi;
import android.app.DownloadManager;
import android.app.PendingIntent;
import android.app.admin.DevicePolicyManager;
Expand Down Expand Up @@ -290,8 +289,7 @@ public String getAppNameFromPackage(String packageName) {

public boolean isPackageInstalled(String packagename) {
try {
PackageInfo packageInfo = packageManager.
getPackageInfo(packagename, 0);
PackageInfo packageInfo = packageManager.getPackageInfo(packagename, 0);
if (packageInfo != null) {
return true;
}
Expand All @@ -318,15 +316,15 @@ private void triggerInstallation(Uri fileUri) {
*
* @param fileUri - File URI should be passed in as a String.
*/
public void startInstallerIntent(Uri fileUri) {
private void startInstallerIntent(Uri fileUri) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
policyManager.isDeviceOwnerApp(Constants.AGENT_PACKAGE)) {
Uri packageFileUri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
packageFileUri = convertContentUriToFileUri(fileUri);
else
} else {
packageFileUri = fileUri;

}
installPackage(packageFileUri);
} else {
boolean isUnknownSourcesDisallowed = Preference.getBoolean(context,
Expand All @@ -337,26 +335,24 @@ public void startInstallerIntent(Uri fileUri) {
intent.setDataAndType(fileUri, resources.getString(R.string.application_mgr_mime));
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(intent);

} else {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(fileUri, resources.getString(R.string.application_mgr_mime));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}

}
}

public Uri convertContentUriToFileUri(Uri contentUri) {
private Uri convertContentUriToFileUri(Uri contentUri) {
String uriString = contentUri.toString();
uriString = "file://" + Environment.getExternalStorageDirectory() +
uriString.replace("content://org.wso2.iot.agent.provider/external_files", "");
return Uri.parse(uriString);
}

@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public boolean installPackage(Uri fileUri) {
private boolean installPackage(Uri fileUri) {

InputStream in;
OutputStream out;
Expand Down Expand Up @@ -537,10 +533,11 @@ public void setupAppDownload(String url, int operationId, String operationCode)
public void uninstallApplication(String packageName, String schedule) throws AndroidAgentException {
String packageUriString = packageName;
if (packageName != null) {
if (!packageName.contains(resources.getString(R.string.application_package_prefix)))
if (!packageName.contains(resources.getString(R.string.application_package_prefix))) {
packageUriString = resources.getString(R.string.application_package_prefix) + packageName;
else
} else {
packageName = packageName.replace(resources.getString(R.string.application_package_prefix), "");
}
}

if (!this.isPackageInstalled(packageName)) {
Expand All @@ -564,10 +561,11 @@ public void uninstallApplication(String packageName, String schedule) throws And
CommonUtils.callSystemApp(context, Constants.Operation.SILENT_UNINSTALL_APPLICATION, "", packageUriString);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
policyManager.isDeviceOwnerApp(Constants.AGENT_PACKAGE)) {
if (silentlyUninstallApplication(packageName))
if (silentlyUninstallApplication(packageName)) {
Preference.putString(context, context.getResources().getString(R.string.app_uninstall_status), APP_STATE_UNINSTALLED);
else
} else {
Preference.putString(context, context.getResources().getString(R.string.app_uninstall_status), APP_STATE_UNINSTALLED_FAILED);
}
Preference.putString(context, context.getResources().getString(R.string.app_uninstall_failed_message), null);
} else {
Preference.putString(context, context.getResources().getString(R.string.app_uninstall_status), APP_STATE_UNINSTALLED);
Expand All @@ -585,7 +583,7 @@ public void uninstallApplication(String packageName, String schedule) throws And
* @param packageName - Application package name should be passed in as a String.
*/
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public boolean silentlyUninstallApplication(String packageName) {
private boolean silentlyUninstallApplication(String packageName) {
PackageInstaller.SessionParams params = new PackageInstaller.SessionParams(
PackageInstaller.SessionParams.MODE_FULL_INSTALL);
params.setAppPackageName(packageName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import android.os.Build;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.support.annotation.RequiresApi;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

Expand Down Expand Up @@ -1187,6 +1188,7 @@ public void processRemoteShell(org.wso2.iot.agent.beans.Operation operation) thr
* @throws TransportHandlerException - Throws when session connection has an error
* @throws JSONException - Throws when error occurs while parsing the payload
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public void screenCapture(org.wso2.iot.agent.beans.Operation operation) throws TransportHandlerException,
JSONException {
String action;
Expand Down Expand Up @@ -1253,6 +1255,7 @@ public void screenCapture(org.wso2.iot.agent.beans.Operation operation) throws T
* @throws TransportHandlerException - Throws when session connection has an error
* @throws JSONException - Throws when error occurs while parsing the payload
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public void processInputInject(org.wso2.iot.agent.beans.Operation operation) throws TransportHandlerException,
JSONException {
if (Constants.SYSTEM_APP_ENABLED && ScreenSharingService.isScreenShared) {
Expand Down

0 comments on commit 09f1c4b

Please sign in to comment.