Package com.mitac.api.libs
Class SystemUtilities
- java.lang.Object
-
- com.mitac.api.libs.ApiBindBase
-
- com.mitac.api.libs.SystemUtilities
-
public class SystemUtilities extends ApiBindBase
This class contains misc functionsFetch Logs Java Sample Code:
package com.mitac.api; import android.app.Activity; import android.os.Bundle; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import com.mitac.api.libs.MitacIntent; import com.mitac.api.libs.SystemUtilities; import com.mitac.api.libs.ServiceStatusCallback; public class MainActivity extends Activity { private SystemUtilities mSystemUtilities; private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) { if (intent != null) { if(MitacIntent.ACTION_LOG_FILES_READY.equals(intent.getAction())){ final boolean isPackOK = intent.getBooleanExtra(MitacIntent.EXTRA_PACK_OK,false ); final String logPath = intent.getStringExtra(MitacIntent.EXTRA_LOG_FILES_PATH); Log.d(TAG, "ACTION_LOG_FILES_READY status: " + isPackOK + " path: " +logPath); if(isPackOK){ // do something here } } } } };@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mSystemUtilities = new SystemUtilities(getApplicationContext(), new ServiceStatusCallback() {@Override
public void ready() { enableLog(true); Logd(TAG, "fetch logs test "); }@Override
public void stopped() { } }); } private void enableLog(boolean enable){ if(mSystemUtilities != null){ mSystemUtilities.setLogServiceEnabled(enable); } } private void fetchLog(int num, boolean stopService, boolean removeFiles){ if(mSystemUtilities != null){ mSystemUtilities.fetchLogs(num, stopService, removeFiles); } }@Override
protected void onResume() { super.onResume(); IntentFilter actions = new IntentFilter(); actions.addAction(MitacIntent.ACTION_LOG_FILES_READY); registerReceiver(mBroadcastReceiver, actions); }@Override
protected void onStop() { super.onStop(); unregisterReceiver(mBroadcastReceiver); } }
-
-
Constructor Summary
Constructors Constructor Description SystemUtilities(android.content.Context context)
This constructor will not bind the service automatically.SystemUtilities(android.content.Context context, ServiceStatusCallback callback)
This constructor will bind the service automatically.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bindService()
bind serviceboolean
fetchLogs(int numberOfLatestFolders, boolean disableLogService, boolean removeSourceLogFiles)
Fetch logfiles package.java.lang.String
getCameraSN(int type)
Get Camera Serial Numberjava.lang.String
getSystemProp(java.lang.String key)
get android system propertiesboolean
isServiceReady()
Check if service is ready.boolean
setDefaultInputMethod(android.content.ComponentName componentName)
Sets default input method.boolean
setLogServiceEnabled(boolean enabled)
Start or stop Log serviceboolean
setSystemProp(java.lang.String key, java.lang.String value)
Sets android system propertiesboolean
setUsbAdbDebug(boolean enable)
To enable or disable USB ADB debug mode.void
unbindService()
unbind service
-
-
-
Constructor Detail
-
SystemUtilities
public SystemUtilities(android.content.Context context)
This constructor will not bind the service automatically. Please callbindService()
at least once before using APIs.- Parameters:
context
- better to useContext.getApplicationContext()
to prevent memory leaks- Throws:
java.lang.IllegalArgumentException
- if context is null.
-
SystemUtilities
public SystemUtilities(android.content.Context context, ServiceStatusCallback callback)
This constructor will bind the service automatically.- Parameters:
context
- better to useContext.getApplicationContext()
to prevent memory leakscallback
- used to get the notification when service is ready.- Throws:
java.lang.IllegalArgumentException
- if context or callback is null.- See Also:
ServiceStatusCallback
-
-
Method Detail
-
bindService
public void bindService()
Description copied from class:ApiBindBase
bind service- Specified by:
bindService
in classApiBindBase
-
unbindService
public void unbindService()
Description copied from class:ApiBindBase
unbind service- Specified by:
unbindService
in classApiBindBase
-
setUsbAdbDebug
public boolean setUsbAdbDebug(boolean enable)
To enable or disable USB ADB debug mode.- Parameters:
enable
-true
to enable USB adb debug;false
otherwise.- Returns:
false
if remote fail.
-
setLogServiceEnabled
public boolean setLogServiceEnabled(boolean enabled)
Start or stop Log serviceLog service will create a folder named logs under the top-level shared/external storage directory.
Here is an example:
Each enable-log-service action, from stop to start, will create a new sub directory under logs to store all log files.{Inner storage root directory} └─ logs ├─ 1.20240409_191516 ├─ 2.20240409_200515 └─ 3.20240409_211005
- Parameters:
enabled
-true
to enable log service;false
otherwise.- Returns:
false
if remote fail.
-
fetchLogs
public boolean fetchLogs(int numberOfLatestFolders, boolean disableLogService, boolean removeSourceLogFiles)
Fetch logfiles package. User can listen to the broadcastMitacIntent.ACTION_LOG_FILES_READY
get the file path of zip file.- Parameters:
numberOfLatestFolders
- the number of latest folders to package, -1 means all listFolderSortByTimeStampdisableLogService
-true
to turn off the log service;false
keep current status and do nothing.removeSourceLogFiles
-true
remove the log folders which are fetched;false
otherwise.- Returns:
false
if remote fail.
-
setDefaultInputMethod
public boolean setDefaultInputMethod(@NonNull android.content.ComponentName componentName)
Sets default input method.- Parameters:
componentName
- The component name of input method.- Returns:
false
if remote fail to set default input method.
-
setSystemProp
public boolean setSystemProp(java.lang.String key, java.lang.String value)
Sets android system properties- Parameters:
key
- property keyvalue
- property value- Returns:
false
if remote fail to set system property.
-
getSystemProp
public java.lang.String getSystemProp(java.lang.String key)
get android system properties- Parameters:
key
- property key- Returns:
null
null means invalid input parameter
-
isServiceReady
public boolean isServiceReady()
Check if service is ready.- Returns:
true
if ready; false otherwise.
-
getCameraSN
public java.lang.String getCameraSN(int type)
Get Camera Serial Number- Parameters:
type
- , int value, 0 means rear camera, 1 means front camera- Returns:
- Serial Number in string, null means invalid input parameter, empty string means no device
-
-