Skip to content

Commit

Permalink
Merge pull request #158 from charithag/master
Browse files Browse the repository at this point in the history
  • Loading branch information
inoshperera authored Feb 20, 2018
2 parents 479fd9e + dc3ba49 commit 10fa83b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 4 deletions.
4 changes: 2 additions & 2 deletions client/client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ android {
targetSdkVersion 25
multiDexEnabled true

versionCode 3010030
versionName "3.1.30"
versionCode 3010031
versionName "3.1.31"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ public void startInstallerIntent(Uri fileUri) {
if(Constants.DEFAULT_OWNERSHIP == Constants.OWNERSHIP_COSU){
installPackage(fileUri);
}else{

boolean isUnknownSourcesDisallowed = Preference.getBoolean(context,
Constants.PreferenceFlag.DISALLOW_UNKNOWN_SOURCES);
CommonUtils.allowUnknownSourcesForProfile(context, !isUnknownSourcesDisallowed);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
intent.setDataAndType(fileUri, resources.getString(R.string.application_mgr_mime));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ public void revokeExistingPolicy(org.wso2.iot.agent.beans.Operation operation)
case Constants.Operation.DISALLOW_DEBUGGING_FEATURES:
case Constants.Operation.DISALLOW_INSTALL_APPS:
case Constants.Operation.DISALLOW_INSTALL_UNKNOWN_SOURCES:
boolean isUnknownSourcesDisallowed = Preference.getBoolean(context,
Constants.PreferenceFlag.DISALLOW_UNKNOWN_SOURCES);
if (isUnknownSourcesDisallowed) {
Preference.putBoolean(context,
Constants.PreferenceFlag.DISALLOW_UNKNOWN_SOURCES, false);
CommonUtils.allowUnknownSourcesForProfile(context, true);
}
case Constants.Operation.DISALLOW_MODIFY_ACCOUNTS:
case Constants.Operation.DISALLOW_OUTGOING_BEAM:
case Constants.Operation.DISALLOW_SHARE_LOCATION:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ public void handleOwnersRestriction(Operation operation) {
String key = operation.getCode();
operation.setStatus(getContextResources().getString(R.string.operation_value_completed));
getResultBuilder().build(operation);
if (Constants.Operation.DISALLOW_INSTALL_UNKNOWN_SOURCES.equals(key)) {
Preference.putBoolean(getContext(),
Constants.PreferenceFlag.DISALLOW_UNKNOWN_SOURCES, isEnable);
CommonUtils.allowUnknownSourcesForProfile(getContext(), !isEnable);
}
if (isEnable) {
getDevicePolicyManager().addUserRestriction(getCdmDeviceAdmin(), getPermissionConstantValue(key));
if (Constants.DEBUG_MODE_ENABLED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import android.location.Location;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.provider.Settings;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.util.Base64;
Expand Down Expand Up @@ -731,4 +733,18 @@ private static int getTimeDistanceInMinutes(long time) {
return Math.round((Math.abs(timeDistance) / 1000) / 60);
}

public static void allowUnknownSourcesForProfile(final Context context, final boolean isEnabled) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
final DevicePolicyManager manager = (DevicePolicyManager) context
.getSystemService(Context.DEVICE_POLICY_SERVICE);
if (manager != null && manager.isProfileOwnerApp(context.getApplicationContext()
.getPackageName())) {
final ComponentName cdmAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class);
manager.setSecureSetting(cdmAdmin, Settings.Secure.INSTALL_NON_MARKET_APPS,
isEnabled ? "1" : "0");
Log.i(TAG, "Enable unknown sources: " + String.valueOf(isEnabled));
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ public final class PreferenceFlag {
public static final String DEVICE_ID_PREFERENCE_KEY = "deviceId";
public static final String LAST_SERVER_CALL = "lastServerCall";
public static final String DEVICE_INITIALIZED = "false";
public static final String DISALLOW_UNKNOWN_SOURCES = "DISALLOW_UNKNOWN_SOURCES";

private PreferenceFlag() {
throw new AssertionError();
Expand Down
2 changes: 1 addition & 1 deletion client/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip

0 comments on commit 10fa83b

Please sign in to comment.