增加绑定网络的接口、实现usb摄像头拍照

serial
BlueMatthew 1 year ago
parent 38bcdd355e
commit 410eff11a9

@ -17,7 +17,7 @@ android {
applicationId "com.xypower.mpapp"
minSdk 25
//noinspection ExpiredTargetSdkVersion
targetSdk 25
targetSdk 28
versionCode AppVersionCode
versionName AppVersionName

@ -1,20 +0,0 @@
{
"version": 3,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "com.xinyingpower.microphoto",
"variantName": "release",
"elements": [
{
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 101010,
"versionName": "1.0.10",
"outputFile": "app-release.apk"
}
],
"elementType": "File"
}

@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
@ -80,6 +81,7 @@
<activity
android:name=".ChannelActivity"
android:exported="false"
android:screenOrientation="landscape"
android:label="@string/activity_channel_title" />
<service
@ -96,7 +98,7 @@
<category android:name="android.intent.category.default" />
</intent-filter>
</service>
<service android:name="com.xypower.common.FloatingWindow" />
<service android:name="com.xypower.mpapp.FloatingWindow" />
<receiver
android:name=".MicroPhotoService$AlarmReceiver"

@ -11,6 +11,8 @@
#include <camera/NdkCameraManager.h>
#include <sys/system_properties.h>
#include <android/multinetwork.h>
#ifdef USING_BREAK_PAD
#include "client/linux/handler/exception_handler.h"
#include "client/linux/handler/minidump_descriptor.h"
@ -168,7 +170,7 @@ Java_com_xypower_mpapp_MainActivity_takePhoto(
extern "C" JNIEXPORT jlong JNICALL
Java_com_xypower_mpapp_MicroPhotoService_init(
JNIEnv* env,
jobject pThis, jstring appPath, jstring ip, jint port, jstring cmdid, jint protocol, jint networkProtocol) {
jobject pThis, jstring appPath, jstring ip, jint port, jstring cmdid, jint protocol, jint networkProtocol, jlong netHandle) {
/*
google_breakpad::MinidumpDescriptor descriptor(".");
@ -177,6 +179,10 @@ Java_com_xypower_mpapp_MicroPhotoService_init(
*/
net_handle_t nh = (net_handle_t)netHandle;
android_setprocnetwork(nh);
char model[PROP_VALUE_MAX] = { 0 };
__system_property_get("ro.product.model", model);
@ -200,7 +206,7 @@ Java_com_xypower_mpapp_MicroPhotoService_init(
CTerminal* pTerminal = NewTerminal(protocol);
CPhoneDevice* device = new CPhoneDevice(vm, pThis, appPathStr);
CPhoneDevice* device = new CPhoneDevice(vm, pThis, appPathStr, NETID_UNSET);
device->SetListener(pTerminal);
pTerminal->InitServerInfo(appPathStr, cmdidStr, ipStr, port, udpOrTcp);

@ -161,7 +161,7 @@ void CPhoneDevice::CPhoneCamera::on_error(const std::string& msg)
}
}
CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPath)
CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPath, unsigned int netId)
{
mCamera = NULL;
m_listener = NULL;
@ -171,6 +171,8 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
m_javaService = NULL;
m_appPath = appPath;
mNetId = netId;
m_vm = vm;
JNIEnv* env = NULL;
bool didAttachThread = false;
@ -197,6 +199,14 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
env->DeleteLocalRef(classService);
jclass classSysApi = env->FindClass("com/dev/devapi/api/SysApi");
if(classSysApi != NULL)
{
mTurnOtg = env->GetStaticMethodID(classSysApi, "setOtgState","(Z)V");
env->DeleteLocalRef(classSysApi);
}
if (didAttachThread)
{
vm->DetachCurrentThread();
@ -204,8 +214,6 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
m_timerUidFeed = time(NULL) * 1000;
m_wakelockIdFeed = (unsigned long)m_timerUidFeed;
}
CPhoneDevice::~CPhoneDevice()
@ -257,6 +265,11 @@ void CPhoneDevice::SetRecognizationCfg(const IDevice::CFG_RECOGNIZATION* pRecogn
m_pRecognizationCfg = pRecognizationCfg;
}
bool CPhoneDevice::BindNetwork(int sock)
{
return true;
}
bool CPhoneDevice::UpdateTime(time_t ts)
{
JNIEnv* env = NULL;
@ -618,9 +631,9 @@ IDevice::timer_uid_t CPhoneDevice::RegisterHeartbeat(unsigned int timerType, uns
ALOGE("Failed to get JNI Env");
return 0;
}
env->CallVoidMethod(m_javaService, mRegisterHeartbeatMid, (jint)timeout);
if (didAttachThread)
{
env->CallVoidMethod(m_javaService, mRegisterHeartbeatMid, (jint)timeout);
m_vm->DetachCurrentThread();
}
@ -649,6 +662,32 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
params.sensibility = mPhotoInfo.sensibility;
params.orientation = mPhotoInfo.orientation;
if (photoInfo.usbCamera)
{
jboolean otgOn = JNI_TRUE;
JNIEnv* env = NULL;
bool didAttachThread = false;
bool res = GetJniEnv(m_vm, &env, didAttachThread);
if (!res)
{
ALOGE("Failed to get JNI Env");
return false;
}
jclass classSysApi = env->FindClass("com/dev/devapi/api/SysApi");
if(classSysApi != NULL)
{
XYLOG(XYLOG_SEVERITY_INFO, "Turn on OTG for USB Camera");
env->CallStaticVoidMethod(classSysApi, mTurnOtg, otgOn);
env->DeleteLocalRef(classSysApi);
}
if (didAttachThread)
{
m_vm->DetachCurrentThread();
}
}
mCamera = new CPhoneCamera(this, photoInfo.width, photoInfo.height, params);
if (mCamera->open(to_string(mPhotoInfo.cameraId).c_str()) == 0)
{

@ -162,11 +162,12 @@ public:
CPhoneDevice* m_dev;
};
CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPath);
CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPath, unsigned int netId);
virtual ~CPhoneDevice();
virtual void SetListener(IListener* listener);
virtual void SetRecognizationCfg(const CFG_RECOGNIZATION* pRecognizationCfg);
virtual bool BindNetwork(int sock);
virtual bool UpdateTime(time_t ts);
virtual bool UpdateSchedules();
virtual bool QuerySystemProperties(map<string, string>& properties);
@ -241,11 +242,14 @@ protected:
jmethodID mEnableGpsMid;
jmethodID mRequestPositionMid;
jmethodID mTurnOtg;
std::string mPath;
IDevice::PHOTO_INFO mPhotoInfo;
vector<IDevice::OSD_INFO> mOsds;
IListener* m_listener;
const CFG_RECOGNIZATION* m_pRecognizationCfg;
unsigned int mNetId;
atomic_ulong m_timerUidFeed;
atomic_ulong m_wakelockIdFeed;

@ -117,8 +117,8 @@ NdkCamera::~NdkCamera()
}
}
int NdkCamera::open(const char* cameraId) {
ALOGW("DBG::open %s", cameraId);
int NdkCamera::open(const std::string& cameraId) {
ALOGW("DBG::open %s", cameraId.c_str());
// camera_facing = _camera_facing;
@ -136,7 +136,7 @@ int NdkCamera::open(const char* cameraId) {
for (int i = 0; i < camera_id_list->numCameras; ++i) {
const char *id = camera_id_list->cameraIds[i];
if (strcmp(id, cameraId) != 0) {
if (cameraId.compare(id) != 0) {
continue;
}
ACameraMetadata * camera_metadata = 0;
@ -164,7 +164,8 @@ int NdkCamera::open(const char* cameraId) {
// continue;
}
camera_id = id;
camera_id = cameraId;
camera_id.assign(id, strlen(id));
// query orientation
int orientation = 0;
@ -177,10 +178,9 @@ int NdkCamera::open(const char* cameraId) {
camera_orientation = orientation;
{
ACameraMetadata_const_entry e = {0};
ACameraMetadata_getConstEntry(camera_metadata,
camera_status_t status = ACameraMetadata_getConstEntry(camera_metadata,
ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, &e);
// format of the data: format, width, height, input?, type int32
@ -299,7 +299,7 @@ int NdkCamera::open(const char* cameraId) {
}
if (camera_id == "2")
{
camera_orientation += 180;
// camera_orientation += 180;
}
mCameraId = camera_id;
@ -658,13 +658,11 @@ void NdkCamera::onCaptureCompleted(ACameraCaptureSession* session, ACaptureReque
ACameraMetadata_const_entry val = { 0 };
camera_status_t status = ACameraMetadata_getConstEntry(result, ACAMERA_SENSOR_EXPOSURE_TIME, &val);
int64_t exTime = val.data.i64[0];
int64_t exTime = (status == ACAMERA_OK) ? val.data.i64[0] : -1;
val = { 0 };
status = ACameraMetadata_getConstEntry(result, ACAMERA_CONTROL_AE_MODE, &val);
uint8_t aeMode = val.data.u8[0];
uint8_t aeMode = (status == ACAMERA_OK) ? val.data.u8[0] : 0;
// ACaptureRequest_setEntry_i32(capture_request, ACAMERA_SENSOR_SENSITIVITY, 1, &sensitivity_);
ALOGD("onCaptureCompleted EXPOSURE_TIME=%lld, camera id=%s, AE=%s", exTime, mCameraId.c_str(), ((aeMode == 1) ? "ON" : "OFF"));

@ -52,7 +52,7 @@ public:
virtual ~NdkCamera();
// facing 0=front 1=back
int open(const char* cameraId);
int open(const std::string& cameraId);
void close();
void onImageAvailable(AImageReader* reader);

@ -135,6 +135,7 @@ public class ChannelActivity extends AppCompatActivity {
}
JSONObject jsonObject = stringBuilder != null ? (new JSONObject(stringBuilder.toString())) : new JSONObject();
binding.btnUsbCamera.setChecked(jsonObject.optInt("usbCamera", 0) == 1);
binding.btnAutoExplosure.setChecked(jsonObject.optInt("autoExposure", 1) == 1);
binding.btnAutoFocus.setChecked(jsonObject.optInt("autoFocus", 1) == 1);
binding.btnHdrMode.setChecked(jsonObject.optInt("hdr", 1) == 1);
@ -248,6 +249,7 @@ public class ChannelActivity extends AppCompatActivity {
}
try {
jsonObject.put("usbCamera", binding.btnUsbCamera.isChecked() ? 1 : 0);
jsonObject.put("autoExposure", binding.btnAutoExplosure.isChecked() ? 1 : 0);
jsonObject.put("autoFocus", binding.btnAutoFocus.isChecked() ? 1 : 0);
jsonObject.put("hdrMode", binding.btnHdrMode.isChecked() ? 1 : 0);

@ -112,6 +112,7 @@ public class MainActivity extends AppCompatActivity {
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
ActionBar actionBar = getSupportActionBar();
@ -223,6 +224,10 @@ public class MainActivity extends AppCompatActivity {
binding.heartbeat.setText((appConfig.heartbeat > 0) ? Integer.toString(appConfig.heartbeat) : "");
binding.packetSize.setText((appConfig.packetSize > 0) ? Integer.toString(appConfig.packetSize) : "");
if (appConfig.network < binding.network.getCount()) {
binding.network.setSelection(appConfig.network);
}
this.binding.startServBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -487,6 +492,7 @@ public class MainActivity extends AppCompatActivity {
intent.putExtra("port", curAppConfig.port);
intent.putExtra("protocol", curAppConfig.protocol);
intent.putExtra("networkProtocol", curAppConfig.networkProtocol);
intent.putExtra("network", curAppConfig.network);
if (messenger != null) {
intent.putExtra("messenger", messenger);
}
@ -508,6 +514,7 @@ public class MainActivity extends AppCompatActivity {
mLogFileObserver = new LogFileObserver(logFilePath);
mLogFileObserver.startWatching();
Log.i(TAG, "Log Observer Started");
}
@Override
@ -518,6 +525,7 @@ public class MainActivity extends AppCompatActivity {
if (mLogFileObserver != null) {
mLogFileObserver.stopWatching();
mLogFileObserver = null;
Log.i(TAG, "Log Observer Stopped");
}
}
@ -559,6 +567,8 @@ public class MainActivity extends AppCompatActivity {
appConfig.heartbeat = TextUtils.isEmpty(binding.heartbeat.getText().toString()) ? 0 : Integer.parseInt(binding.heartbeat.getText().toString());
appConfig.packetSize = TextUtils.isEmpty(binding.packetSize.getText().toString()) ? 0 : Integer.parseInt(binding.packetSize.getText().toString());
appConfig.network = MainActivity.this.binding.network.getSelectedItemPosition();
saveAppConfig(appConfig);
return appConfig;

@ -1,5 +1,6 @@
package com.xypower.mpapp;
import static java.lang.System.in;
import static java.lang.System.loadLibrary;
import android.app.AlarmManager;
@ -18,6 +19,10 @@ import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkRequest;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.BatteryManager;
@ -553,43 +558,51 @@ public class MicroPhotoService extends Service {
mMessenger = intent.getParcelableExtra("messenger");
}
String appPath = MicroPhotoContext.buildAppDir(this.getApplicationContext());
String server = intent.getStringExtra("server");
int port = intent.getIntExtra("port", 0);
String cmdid = intent.getStringExtra("cmdid");
int protocol = intent.getIntExtra("protocol", 0);
int networkProtocol = intent.getIntExtra("networkProtocol", 0);
if (!InetAddressUtils.isIPv4Address(server) && !InetAddressUtils.isIPv6Address(server)) {
// It is a domain
InetAddress addr = null;
try {
addr = InetAddress.getByName(server);
} catch (Exception e) {
e.printStackTrace();
}
if (addr != null) {
server = addr.getHostAddress();
}
}
Log.i(TAG, "AppPath=" + appPath + " Server=" + server + ":" + port + " cmdid=" + cmdid + " Protocol=" + protocol + " Network=" + networkProtocol);
int network = intent.getIntExtra("network", 0);
if (network == 0) {
startTerminalService(intent);
} else {
ConnectivityManager cm =(ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkRequest.Builder builder = new NetworkRequest.Builder();
builder.addCapability(NetworkCapabilities.NET_CAPABILITY_DUN);
builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
List<NetworkInfo> availableNetworkInfos = new ArrayList<>();
cm.registerNetworkCallback(builder.build(), new ConnectivityManager.NetworkCallback() {
MicroPhotoService service = MicroPhotoService.this;
@Override
public void onAvailable(Network network) {
super.onAvailable(network);
service.mNativeHandle = init(appPath, server, port, cmdid, protocol, networkProtocol);
availableNetworkInfos.add(cm.getNetworkInfo(network));
if (service.mNativeHandle !=0) {
service.mCmdid = cmdid;
Date date = new Date();
long nowTs = date.getTime() / 1000;
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
long startTime = date.getTime() / 1000;
long baseTime = nowTs - startTime;
Log.i(TAG, "Network");
}
service.registerCaptureSchedule(startTime, baseTime);
});
NetworkInfo[] networkInfos = cm.getAllNetworkInfo();
for (NetworkInfo ni : networkInfos) {
if (ni.getType() == ConnectivityManager.TYPE_MOBILE ||
ni.getType() == ConnectivityManager.TYPE_MOBILE_DUN ||
ni.getType() == ConnectivityManager.TYPE_WIFI) {
// availableNetworkInfos.add(ni);
}
}
Network[] networks = cm.getAllNetworks();
for (Network nw : networks) {
NetworkInfo nwi = cm.getNetworkInfo(nw);
String name = nwi.toString();
if (name.equals("")) {
}
}
}
break;
@ -607,6 +620,48 @@ public class MicroPhotoService extends Service {
return START_NOT_STICKY;
}
private void startTerminalService(Intent intent) {
String appPath = MicroPhotoContext.buildAppDir(this.getApplicationContext());
String server = intent.getStringExtra("server");
int port = intent.getIntExtra("port", 0);
String cmdid = intent.getStringExtra("cmdid");
int protocol = intent.getIntExtra("protocol", 0);
int networkProtocol = intent.getIntExtra("networkProtocol", 0);
if (!InetAddressUtils.isIPv4Address(server) && !InetAddressUtils.isIPv6Address(server)) {
// It is a domain
InetAddress addr = null;
try {
addr = InetAddress.getByName(server);
} catch (Exception e) {
e.printStackTrace();
}
if (addr != null) {
server = addr.getHostAddress();
}
}
Log.i(TAG, "AppPath=" + appPath + " Server=" + server + ":" + port + " cmdid=" + cmdid + " Protocol=" + protocol + " Network=" + networkProtocol);
MicroPhotoService service = MicroPhotoService.this;
service.mNativeHandle = init(appPath, server, port, cmdid, protocol, networkProtocol, 0);
if (service.mNativeHandle !=0) {
service.mCmdid = cmdid;
Date date = new Date();
long nowTs = date.getTime() / 1000;
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
long startTime = date.getTime() / 1000;
long baseTime = nowTs - startTime;
service.registerCaptureSchedule(startTime, baseTime);
}
}
public void requestWakelock(String name, long timeout) {
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
PowerManager.WakeLock wl = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK/* | PowerManager.ON_AFTER_RELEASE*/, name);
@ -923,7 +978,7 @@ CellSignalStrengthGsm cellSignalStrengthGsm = cellInfoGsm.getCellSignalStrength(
cellSignalStrengthGsm.getDbm();
*/
protected native long init(String appPath, String ip, int port, String cmdid, int protocol, int networkProtocl);
protected native long init(String appPath, String ip, int port, String cmdid, int protocol, int networkProtocl, long netHandle);
protected native long getHeartbeatDuration(long handler);
protected native long[] getPhotoTimeData(long handler);
// protected native long[] getNextScheduleItem(long handler);

@ -140,6 +140,17 @@
app:layout_constraintLeft_toRightOf="@+id/textViewPacketSize"
app:layout_constraintTop_toBottomOf="@+id/server" />
<Spinner
android:id="@+id/network"
style="@style/Widget.AppCompat.Spinner.Underlined"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/networks"
android:spinnerMode="dropdown"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toRightOf="@+id/packetSize"
app:layout_constraintTop_toTopOf="@+id/heartbeat" />
<Button
android:id="@+id/startServBtn"
android:layout_width="wrap_content"

@ -30,6 +30,16 @@
app:layout_constraintTop_toTopOf="@+id/channels"
app:layout_constraintBottom_toBottomOf="@+id/channels" />
<Switch
android:id="@+id/btnUsbCamera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="6dp"
android:text="@string/channel_cfg_usb_camera"
app:layout_constraintStart_toEndOf="@+id/cameraId"
app:layout_constraintTop_toTopOf="@+id/cameraId" />
<Button
android:id="@+id/btnSave"
android:layout_width="wrap_content"

@ -55,7 +55,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:ems="10"
android:inputType="none"
android:inputType="none|text"
android:text="47.96.238.157"
app:layout_constraintStart_toStartOf="@+id/cmdid"
app:layout_constraintTop_toBottomOf="@+id/cmdid" />
@ -132,6 +132,17 @@
app:layout_constraintLeft_toRightOf="@+id/textViewPacketSize"
app:layout_constraintTop_toBottomOf="@+id/server" />
<Spinner
android:id="@+id/network"
style="@style/Widget.AppCompat.Spinner.Underlined"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/networks"
android:spinnerMode="dropdown"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toRightOf="@+id/packetSize"
app:layout_constraintTop_toTopOf="@+id/heartbeat" />
<Button
android:id="@+id/startServBtn"
android:layout_width="wrap_content"
@ -140,9 +151,7 @@
android:layout_marginTop="8dp"
android:text="Start"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/heartbeat"
/>
app:layout_constraintTop_toBottomOf="@+id/heartbeat" />
<Button
android:id="@+id/stopServBtn"
@ -175,8 +184,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/startServBtn" />
<Button
android:id="@+id/simchange2"
android:layout_width="wrap_content"
@ -227,7 +234,6 @@
app:layout_constraintStart_toEndOf="@+id/takePhotoBtn2"
app:layout_constraintTop_toBottomOf="@+id/simchange" />
<Button
android:id="@+id/takePhotoBtn4"
android:layout_width="wrap_content"

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="networks">
<item>当前网络</item>
<item>SIM1</item>
<item>SIM2</item>
<item>WIFI</item>
</string-array>
</resources>

@ -22,6 +22,7 @@
<string name="channel_cfg_width">照片宽</string>
<string name="channel_cfg_height">照片高</string>
<string name="channel_cfg_quality">压缩率(50-100)</string>
<string name="channel_cfg_usb_camera">USB Camera</string>

@ -3,11 +3,11 @@ plugins {
}
android {
compileSdk 32
compileSdk 33
defaultConfig {
minSdk 25
targetSdk 32
targetSdk 28
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"

@ -25,6 +25,16 @@ public class MicroPhotoContext {
public final static String MASTER_URL_CMDID = "cmdid";
public final static int DEFAULT_PROTOCOL = 0xFF00;
public static class AppConfig {
public String cmdid;
public String server;
public int port;
public int protocol;
public int networkProtocol;
public int network; // 0: SIM1 1: SIM2 2: WIFI
public int heartbeat;
public int packetSize;
}
public static String buildAppDir(Context contxt) {
@ -84,6 +94,7 @@ public class MicroPhotoContext {
appConfig.port = jsonObject.optInt("Port", 0);
appConfig.protocol = jsonObject.optInt("Protocol", DEFAULT_PROTOCOL);
appConfig.networkProtocol = jsonObject.optInt("NetworkProtocol", 0);
appConfig.network = jsonObject.optInt("Network", 0);
appConfig.heartbeat = jsonObject.optInt("heartbeat", 0);
appConfig.packetSize = jsonObject.optInt("packetSize", 0);
@ -141,6 +152,7 @@ public class MicroPhotoContext {
appConfig.port = jsonObject.optInt("Port", 0);
appConfig.protocol = jsonObject.optInt("Protocol", DEFAULT_PROTOCOL);
appConfig.networkProtocol = jsonObject.optInt("NetworkProtocol", 0);
appConfig.network = jsonObject.optInt("Network", 0);
appConfig.heartbeat = jsonObject.optInt("heartbeat", 0);
appConfig.packetSize = jsonObject.optInt("packetSize", 0);
@ -203,6 +215,7 @@ public class MicroPhotoContext {
jsonObject.put("Port", appConfig.port);
jsonObject.put("Protocol", appConfig.protocol);
jsonObject.put("NetworkProtocol", appConfig.networkProtocol);
jsonObject.put("Network", appConfig.network);
if (appConfig.heartbeat > 0) {
jsonObject.put("heartbeat", appConfig.heartbeat);
@ -303,6 +316,7 @@ public class MicroPhotoContext {
jsonObject.put("Port", appConfig.port);
jsonObject.put("Protocol", appConfig.protocol);
jsonObject.put("NetworkProtocol", appConfig.networkProtocol);
jsonObject.put("Network", appConfig.network);
if (appConfig.heartbeat > 0) {
jsonObject.put("heartbeat", appConfig.heartbeat);
@ -357,13 +371,5 @@ public class MicroPhotoContext {
return verName;
}
public static class AppConfig {
public String cmdid;
public String server;
public int port;
public int protocol;
public int networkProtocol;
public int heartbeat;
public int packetSize;
}
}

@ -0,0 +1,305 @@
package com.xypower.common;
import android.content.Context;
import android.os.Build;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import java.lang.reflect.Method;
import java.util.List;
public class TelephonyInfo {
private static TelephonyInfo telephonyInfo;
private String imeiSIM1;
private String imeiSIM2;
private String imsiSIM1;
private String imsiSIM2;
private String iccidSIM1;
private String iccidSIM2;
private boolean isSIM1Ready;
private boolean isSIM2Ready;
private String numberSIM1;
private String numberSIM2;
private int mcc1;
private int mcc2;
private int mnc1;
private int mnc2;
private int defaultSimm;
private int smsDefaultSimm;
public String getNumberSIM1() {
return numberSIM1 == null ? "" : numberSIM1;
}
public String getNumberSIM2() {
return numberSIM2 == null ? "" : numberSIM2;
}
public String getImeiSIM1() {
return imeiSIM1 == null ? "" : imeiSIM1;
}
public String getImeiSIM2() {
return imeiSIM2 == null ? "" : imeiSIM2;
}
public String getImsiSIM1() {
return imsiSIM1 == null ? "" : imsiSIM1;
}
public String getImsiSIM2() {
return imsiSIM2 == null ? "" : imsiSIM2;
}
public String getIccidSIM1() {
return iccidSIM1 == null ? "" : iccidSIM1;
}
public String getIccidSIM2() {
return iccidSIM2 == null ? "" : iccidSIM2;
}
public boolean isSIM1Ready() {
return isSIM1Ready;
}
public boolean isSIM2Ready() {
return isSIM2Ready;
}
public boolean isDualSIM() {
return imeiSIM2 != null && !imeiSIM2.equals("");
}
public int getMcc1() {
return mcc1;
}
public int getMcc2() {
return mcc2;
}
public int getMnc1() {
return mnc1;
}
public int getMnc2() {
return mnc2;
}
public int getDefaultSimm() {
return defaultSimm;
}
public int getSmsDefaultSimm() {
return smsDefaultSimm;
}
private TelephonyInfo() {
}
public static TelephonyInfo getInstance(Context context) {
if (telephonyInfo == null) {
telephonyInfo = new TelephonyInfo();
TelephonyManager telephonyManager = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE));
telephonyInfo.imeiSIM1 = telephonyManager.getDeviceId();
telephonyInfo.imeiSIM2 = "";
telephonyInfo.imsiSIM1 = telephonyManager.getSubscriberId();
telephonyInfo.imsiSIM2 = "";
telephonyInfo.iccidSIM1 = telephonyManager.getSimSerialNumber();
telephonyInfo.iccidSIM2 = "";
telephonyInfo.numberSIM1 = "";
telephonyInfo.numberSIM2 = "";
telephonyInfo.defaultSimm = -1;
telephonyInfo.smsDefaultSimm = -1;
telephonyInfo.isSIM1Ready = telephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY;
telephonyInfo.isSIM2Ready = false;
try {
telephonyInfo.isSIM1Ready = getSIMStateBySlot(context, "getSimStateGemini", 0);
telephonyInfo.isSIM2Ready = getSIMStateBySlot(context, "getSimStateGemini", 1);
} catch (GeminiMethodNotFoundException e) {
e.printStackTrace();
try {
telephonyInfo.isSIM1Ready = getSIMStateBySlot(context, "getSimState", 0);
telephonyInfo.isSIM2Ready = getSIMStateBySlot(context, "getSimState", 1);
} catch (GeminiMethodNotFoundException e1) {
//Call here for next manufacturer's predicted method name if you wish
e1.printStackTrace();
}
}
try {
telephonyInfo.imeiSIM1 = getDeviceIdBySlot(context, "getDeviceIdGemini", 0);
telephonyInfo.imeiSIM2 = getDeviceIdBySlot(context, "getDeviceIdGemini", 1);
} catch (GeminiMethodNotFoundException e) {
e.printStackTrace();
try {
telephonyInfo.imeiSIM1 = getDeviceIdBySlot(context, "getDeviceId", 0);
telephonyInfo.imeiSIM2 = getDeviceIdBySlot(context, "getDeviceId", 1);
} catch (GeminiMethodNotFoundException e1) {
//Call here for next manufacturer's predicted method name if you wish
e1.printStackTrace();
}
}
try {
telephonyInfo.imsiSIM1 = getDeviceIdBySlot(context, "getSubscriberIdGemini", 0);
telephonyInfo.imsiSIM2 = getDeviceIdBySlot(context, "getSubscriberIdGemini", 1);
} catch (GeminiMethodNotFoundException e) {
e.printStackTrace();
try {
telephonyInfo.imsiSIM1 = getDeviceIdBySlot(context, "getSubscriberId", 0);
telephonyInfo.imsiSIM2 = getDeviceIdBySlot(context, "getSubscriberId", 1);
} catch (GeminiMethodNotFoundException e1) {
//Call here for next manufacturer's predicted method name if you wish
e1.printStackTrace();
}
}
try {
telephonyInfo.iccidSIM1 = getDeviceIdBySlot(context, "getSimSerialNumberGemini", 0);
telephonyInfo.iccidSIM2 = getDeviceIdBySlot(context, "getSimSerialNumberGemini", 1);
} catch (GeminiMethodNotFoundException e) {
e.printStackTrace();
try {
telephonyInfo.iccidSIM1 = getDeviceIdBySlot(context, "getSimSerialNumber", 0);
telephonyInfo.iccidSIM2 = getDeviceIdBySlot(context, "getSimSerialNumber", 1);
} catch (GeminiMethodNotFoundException e1) {
//Call here for next manufacturer's predicted method name if you wish
e1.printStackTrace();
}
}
Object tm = context.getSystemService(Context.TELEPHONY_SERVICE);
Method method_getDefaultSim;
try {
method_getDefaultSim = tm.getClass().getDeclaredMethod("getDefaultSim");
method_getDefaultSim.setAccessible(true);
telephonyInfo.defaultSimm = (Integer) method_getDefaultSim.invoke(tm);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Method method_getSmsDefaultSim;
try {
method_getSmsDefaultSim = tm.getClass().getDeclaredMethod("getSmsDefaultSim");
telephonyInfo.smsDefaultSimm = (Integer) method_getSmsDefaultSim.invoke(tm);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
SubscriptionManager sm = SubscriptionManager.from(context);
// it returns a list with a SubscriptionInfo instance for each simcard
// there is other methods to retrieve SubscriptionInfos (see [2])
List<SubscriptionInfo> sis = sm.getActiveSubscriptionInfoList();
telephonyInfo.iccidSIM1 = "";
telephonyInfo.iccidSIM2 = "";
if (sis != null) {
for (int i = 0; i < sis.size(); i++) {
SubscriptionInfo si = sis.get(i);
if (si.getSimSlotIndex() == 0) {
telephonyInfo.iccidSIM1 = si.getIccId();
telephonyInfo.numberSIM1 = si.getNumber();
telephonyInfo.mcc1 = si.getMcc();
telephonyInfo.mnc1 = si.getMnc();
} else {
telephonyInfo.iccidSIM2 = si.getIccId();
telephonyInfo.numberSIM2 = si.getNumber();
telephonyInfo.mcc2 = si.getMcc();
telephonyInfo.mnc2 = si.getMnc();
}
}
}
}
}
return telephonyInfo;
}
private static String getDeviceIdBySlot(Context context, String predictedMethodName, int slotID) throws GeminiMethodNotFoundException {
String imei = null;
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class<?> telephonyClass = Class.forName(telephony.getClass().getName());
Class<?>[] parameter = new Class[1];
parameter[0] = int.class;
Method getSimID = telephonyClass.getMethod(predictedMethodName, parameter);
Object[] obParameter = new Object[1];
obParameter[0] = slotID;
Object ob_phone = getSimID.invoke(telephony, obParameter);
if(ob_phone != null){
imei = ob_phone.toString();
}
} catch (Exception e) {
e.printStackTrace();
throw new GeminiMethodNotFoundException(predictedMethodName);
}
return imei;
}
private static boolean getSIMStateBySlot(Context context, String predictedMethodName, int slotID) throws GeminiMethodNotFoundException {
boolean isReady = false;
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class<?> telephonyClass = Class.forName(telephony.getClass().getName());
Class<?>[] parameter = new Class[1];
parameter[0] = int.class;
Method getSimStateGemini = telephonyClass.getMethod(predictedMethodName, parameter);
Object[] obParameter = new Object[1];
obParameter[0] = slotID;
Object ob_phone = getSimStateGemini.invoke(telephony, obParameter);
if(ob_phone != null){
int simState = Integer.parseInt(ob_phone.toString());
if(simState == TelephonyManager.SIM_STATE_READY){
isReady = true;
}
}
} catch (Exception e) {
e.printStackTrace();
throw new GeminiMethodNotFoundException(predictedMethodName);
}
return isReady;
}
private static class GeminiMethodNotFoundException extends Exception {
private static final long serialVersionUID = -996812356902545308L;
public GeminiMethodNotFoundException(String info) {
super(info);
}
}
}

@ -15,7 +15,7 @@ android {
defaultConfig {
applicationId "com.xypower.mpmaster"
minSdk 25
targetSdk 25
targetSdk 28
versionCode AppVersionCode
versionName AppVersionName

@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

@ -0,0 +1,224 @@
package com.xypower.mpapp;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.os.IBinder;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.xypower.mpmaster.R;
public class FloatingWindow extends Service {
private Context mContext;
private WindowManager mWindowManager;
private View mView;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
mContext = this;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
allAboutLayout(intent);
moveView();
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
try {
if (mView != null) {
mWindowManager.removeView(mView);
}
} catch (Exception ex) {
// ex.printStackTrace();
Log.e("FW", "Exception " + ex.getMessage());
}
super.onDestroy();
}
WindowManager.LayoutParams mWindowsParams;
private void moveView() {
/*
DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
int width = (int) (metrics.widthPixels * 1f);
int height = (int) (metrics.heightPixels * 1f);
mWindowsParams = new WindowManager.LayoutParams(
width,//WindowManager.LayoutParams.WRAP_CONTENT,
height,//WindowManager.LayoutParams.WRAP_CONTENT,
//WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
(Build.VERSION.SDK_INT <= 25) ? WindowManager.LayoutParams.TYPE_PHONE : WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
,
//WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN // Not displaying keyboard on bg activity's EditText
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
//WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, //Not work with EditText on keyboard
PixelFormat.TRANSLUCENT);
mWindowsParams.gravity = Gravity.TOP | Gravity.LEFT;
//params.x = 0;
mWindowsParams.y = 100;
mWindowManager.addView(mView, mWindowsParams);
mView.setOnTouchListener(new View.OnTouchListener() {
private int initialX;
private int initialY;
private float initialTouchX;
private float initialTouchY;
long startTime = System.currentTimeMillis();
@Override
public boolean onTouch(View v, MotionEvent event) {
if (System.currentTimeMillis() - startTime <= 300) {
return false;
}
if (isViewInBounds(mView, (int) (event.getRawX()), (int) (event.getRawY()))) {
editTextReceiveFocus();
} else {
editTextDontReceiveFocus();
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
initialX = mWindowsParams.x;
initialY = mWindowsParams.y;
initialTouchX = event.getRawX();
initialTouchY = event.getRawY();
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_MOVE:
mWindowsParams.x = initialX + (int) (event.getRawX() - initialTouchX);
mWindowsParams.y = initialY + (int) (event.getRawY() - initialTouchY);
mWindowManager.updateViewLayout(mView, mWindowsParams);
break;
}
return false;
}
});
*/
}
private boolean isViewInBounds(View view, int x, int y) {
Rect outRect = new Rect();
int[] location = new int[2];
view.getDrawingRect(outRect);
view.getLocationOnScreen(location);
outRect.offset(location[0], location[1]);
return outRect.contains(x, y);
}
private void editTextReceiveFocus() {
if (!wasInFocus) {
mWindowsParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
mWindowManager.updateViewLayout(mView, mWindowsParams);
wasInFocus = true;
}
}
private void editTextDontReceiveFocus() {
if (wasInFocus) {
mWindowsParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
mWindowManager.updateViewLayout(mView, mWindowsParams);
wasInFocus = false;
hideKeyboard(mContext, edt1);
}
}
private boolean wasInFocus = true;
private EditText edt1;
private void allAboutLayout(Intent intent) {
LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mView = layoutInflater.inflate(R.layout.ovelay_window, null);
edt1 = (EditText) mView.findViewById(R.id.edt1);
final TextView tvValue = (TextView) mView.findViewById(R.id.tvValue);
Button btnClose = (Button) mView.findViewById(R.id.btnClose);
edt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mWindowsParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
mWindowsParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE;
mWindowManager.updateViewLayout(mView, mWindowsParams);
wasInFocus = true;
showSoftKeyboard(v);
}
});
edt1.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
tvValue.setText(edt1.getText());
}
@Override
public void afterTextChanged(Editable editable) {
}
});
btnClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
stopSelf();
}
});
}
private void hideKeyboard(Context context, View view) {
if (view != null) {
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
public void showSoftKeyboard(View view) {
if (view.requestFocus()) {
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}
}
}

@ -311,7 +311,6 @@ public class AppMaster {
if (response != null) {
}
} catch (Exception ex) {
}

Loading…
Cancel
Save