From 01abe1716bf708b8e1a4600ef7fa209eeb91a686 Mon Sep 17 00:00:00 2001 From: quentinhardy Date: Sun, 8 Jan 2017 09:56:08 -0500 Subject: [PATCH] Useful Android functions (Utils module) --- pupy/packages/android/pupydroid/utils.py | 66 ++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 pupy/packages/android/pupydroid/utils.py diff --git a/pupy/packages/android/pupydroid/utils.py b/pupy/packages/android/pupydroid/utils.py new file mode 100644 index 00000000..08980ba5 --- /dev/null +++ b/pupy/packages/android/pupydroid/utils.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python +# -*- coding: UTF8 -*- +#Author: @bobsecq +#Contributor(s): + +import jnius +from jnius import autoclass, PythonJavaClass, java_method, cast + +def getAndroidID(): + pythonActivity = autoclass('org.renpy.android.PythonService') + settingsSecure = autoclass('android.provider.Settings$Secure') + androidId = settingsSecure.getString(pythonActivity.mService.getContentResolver(), settingsSecure.ANDROID_ID) + return androidId + +def getPhoneNumber(): + mContext = autoclass('android.content.Context') + pythonActivity = autoclass('org.renpy.android.PythonService') + telephonyManager = cast('android.telephony.TelephonyManager', pythonActivity.mService.getSystemService(mContext.TELEPHONY_SERVICE)) + phoneNumber = telephonyManager.getLine1Number(); + return phoneNumber + +def isWiFiEnabled(): + mContext = autoclass('android.content.Context') + pythonActivity = autoclass('org.renpy.android.PythonService') + wifiManager = cast('android.net.wifi.WifiManager', pythonActivity.mService.getSystemService(mContext.WIFI_SERVICE)) + return wifiManager.isWifiEnabled() + +def isWiFiConnected(): + mContext = autoclass('android.content.Context') + pythonActivity = autoclass('org.renpy.android.PythonService') + connectivityManager = autoclass('android.net.ConnectivityManager') + cManager = cast('android.net.ConnectivityManager', pythonActivity.mService.getSystemService(mContext.CONNECTIVITY_SERVICE)) + networkInfo = cManager.getNetworkInfo(connectivityManager.TYPE_WIFI); + return networkInfo.isConnected() + +def isVPNConnected(): + mContext = autoclass('android.content.Context') + pythonActivity = autoclass('org.renpy.android.PythonService') + connectivityManager = autoclass('android.net.ConnectivityManager') + cManager = cast('android.net.ConnectivityManager', pythonActivity.mService.getSystemService(mContext.CONNECTIVITY_SERVICE)) + try: + networkInfo = cManager.getNetworkInfo(connectivityManager.TYPE_VPN); + except Exception, e: + return False + return networkInfo.isConnected() + +def getInfoBuild(): + build = autoclass('android.os.Build') + deviceName = build.DEVICE + manufacturer = build.MANUFACTURER + model = build.MODEL + product = build.PRODUCT + bootloaderVersion = build.BOOTLOADER + hardware = build.HARDWARE + try: + serial = build.SERIAL + except Exception,e: + serial = None + radioVersion = build.getRadioVersion() + return {'deviceName':deviceName, 'manufacturer':manufacturer, 'model':model, 'product': product, 'bootloaderVersion':bootloaderVersion, 'hardware':hardware, 'serial':serial, 'radioVersion':radioVersion} + + + + + +