Android examples for Android OS:Shell
check Multi User Enabled in Shell
/*/* ww w.j a va2 s . c om*/ * Copyright 2014 Great Bytes Software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ //package com.java2s; import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStream; import android.util.Log; public class Main { public static String TAG = "TerminalUtils"; private static final int BUFF_LEN = 4096; public static boolean checkMultiUserEnabled() { try { Process p = Runtime.getRuntime().exec("pm get-max-users\n"); DataOutputStream os = new DataOutputStream(p.getOutputStream()); os.flush(); InputStream is = p.getInputStream(); byte[] buffer = new byte[BUFF_LEN]; int read; String out = new String(); //read method will wait forever if there is nothing in the stream while (true) { read = is.read(buffer); out += new String(buffer, 0, read); if (read < BUFF_LEN) { //we have read everything break; } } //Log.i(TAG, "out: " + out); if (out.contains("Maximum supported users:")) { out = out.replace("\n", "").replace("\r", ""); String[] maxUsers = out.split(": "); if (Integer.valueOf(maxUsers[1]) == 1) { //Multiuser feature is disabled return false; } else { //Multiuser feature is enabled return true; } } } catch (IOException e) { Log.e(TAG, "checkMultiUserEnabled IOException: " + e.getMessage()); } catch (Exception e) { Log.e(TAG, "checkMultiUserEnabled Exception: " + e.getMessage()); } return false; } }