android how to check if device supports Sview - android

How can we determine if given android device supports S-view or not ?
Is there any way programatically or through adb command ? So that we can check if device supports sview and to check its status when it will be shown.
Any guidelines or help would be greatly appreciated.
EDIT :
I added workaround below for this check.
Also if someone has different approach please let me know.

I have got workaround for this,
These are extra features added by samsung for the devices for which no constant values are added in Android api, so we need to add them manually.
private static final String SVIEW_FEATURE = "com.sec.feature.cover.sview";
private static final String HOVER_FEATURE = "com.sec.feature.hovering_ui";
private static final String SENSOR_HUB_FEATURE = "com.sec.feature.sensorhub";
private static final String SPEN_FEATURE = "com.sec.feature.spen_usp";
You can call below function as ,
hasFeature(SPEN_FEATURE );
Function :
private boolean hasFeature(String feature) {
FeatureInfo[] infos = getPackageManager().getSystemAvailableFeatures();
for (FeatureInfo info : infos) {
if (!TextUtils.isEmpty(info.name)) {
Log.d("TAG", info.name);
if (feature.equalsIgnoreCase(info.name)) {
Log.v("TAG", "Feature supported "+ info.name);
return true;
}
}
}
return false;
}

Check the link below, it could be helpful to you. As android doesn't support S view directly.
s-view functionality on any phone

Related

How does Snapchat detect XPosed Framework?

I tried to install Snapchat on my newly rooted and Xposed smartphone. But the login is impossible as Snapchat detects Xposed Framework.
I "understand" the reason of this restriction, even though I think it's a bit too much as I don't use Xposed for Snapchat.
But my question is: How do they detect the Framework ?
SnapChat uses Google's SafetyNet Attestation API and does not specifically check if XPosed is installed. SnapChat runs SafetyNet the first time the app is launched.
To make sure SnapChat does not specifically check for the XPosed framework, I decompiled Snapchat and ran grep -lri xposed. The search came up with no results.
Checking if XPosed is installed:
I'm sure there are plenty of ways you could check if Xposed is installed. I wrote the following method which gets the currently installed Xposed version or returns null if the XposedBridge.jar was not found on the device:
/**
* Get the current Xposed version installed on the device.
*
* #param context The application context
* #return The Xposed version or {#code null} if Xposed isn't installed.
*/
public static Integer getXposedVersion(Context context) {
try {
File xposedBridge = new File("/system/framework/XposedBridge.jar");
if (xposedBridge.exists()) {
File optimizedDir = context.getDir("dex", Context.MODE_PRIVATE);
DexClassLoader dexClassLoader = new DexClassLoader(xposedBridge.getPath(),
optimizedDir.getPath(), null, ClassLoader.getSystemClassLoader());
Class<?> XposedBridge = dexClassLoader.loadClass("de.robv.android.xposed.XposedBridge");
Method getXposedVersion = XposedBridge.getDeclaredMethod("getXposedVersion");
if (!getXposedVersion.isAccessible()) getXposedVersion.setAccessible(true);
return (Integer) getXposedVersion.invoke(null);
}
} catch (Exception ignored) {
}
return null;
}
As far as I can tell, Xposed has always had XposedBridge.jar in /system/framework so this should work for the official releases of Xposed but could break in future releases.
I believe Snapchat uses SafetyNet, the API which also protects Android Pay and Pokemon GO.
Xposed can be checked by reflect,in class XposedHelper
public class XposedHelper {
private static final String LOGTAG = "XposedHelpers";
private static final HashMap<String, Field> fieldCache = new HashMap<>();
private static final HashMap<String, Method> methodCache = new HashMap<>();
private static final HashMap<String, Constructor<?>> constructorCache = new HashMap<>();
private static final WeakHashMap<Object, HashMap<String, Object>> additionalFields = new WeakHashMap<>();
private static final HashMap<String, ThreadLocal<AtomicInteger>> sMethodDepth = new HashMap<>();
}
check if contains your app info in these parameter.

unable to send a notification to myself

After I followed all the steps for the push notification sample app. I wasn't able to send a notifaction to myself. I could send a pushmessage from my PC to my phone, but when I use the button Send myself a Notification nothing happens.
I am using Android sdk
After starting the app I do see that my Device is Registerd
Here is my settings.java
package com.ganyo.pushtest;
/** Change these values to match your setup! */
public class Settings {
static final String UNASSIGNED_ORG_VALUE = "";
// Google Client Id from Google API Console
static final String GCM_SENDER_ID = "xxxxxxxxxxxxx";
// Notifier Name in App Services
static final String NOTIFIER = "androidDev";
static final String API_URL = "https://api.usergrid.com";
static final String ORG = "xxxxxxx";
static final String APP = "sandbox";
// set these if you want to use a user login
static final String USER = null;
static final String PASSWORD = null;
}
I'm not sure what the UNASSIGNED_ORG_VALUE should be.
Thx in advance.
No need to assign any value to UNASSIGNED_ORG_VALUE. It's only used to check that you've entered the other values.
Please check your Android logs as well as the Apigee Console to see what error messages might have been generated during your push attempt. This will help you debug the issue.
Finally, you could try providing your notifier name here in all lowercase. (Note: This shouldn't generally be necessary, but I've heard there may be a issue that affects notifier name resolution.)

Android development: disable "show notification" programmatically with root permission?

Is there a way to programmatically change the details (Settings -> Apps -> [anApp]) of an app?
Specifically, can I uncheck "show notification"?
I assume that you have root permissions
thanks in advance for help
Firstly it seems that it depends on which version of Android you are interested in. It seems that things changed in 4.3. I am investigating the latest master branch (which is l-preview), so going down the AOSP rabbit hole we find...
In the Settings package...
InstalledAppDetails.java:1299
private void setNotificationsEnabled(boolean enabled) {
String packageName = mAppEntry.info.packageName;
INotificationManager nm = INotificationManager.Stub.asInterface(
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
try {
final boolean enable = mNotificationSwitch.isChecked();
nm.setNotificationsEnabledForPackage(packageName, mAppEntry.info.uid, enabled);
} catch (android.os.RemoteException ex) {
mNotificationSwitch.setChecked(!enabled); // revert
}
}
In frameworks/base...
NotificationManagerService.java:454
public void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled) {
checkCallerIsSystem();
Slog.v(TAG, (enabled?"en":"dis") + "abling notifications for " + pkg);
mAppOps.setMode(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg,
enabled ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_IGNORED);
// Now, cancel any outstanding notifications that are part of a just-disabled app
if (ENABLE_BLOCKED_NOTIFICATIONS && !enabled) {
cancelAllNotificationsInt(pkg, 0, 0, true, UserHandle.getUserId(uid));
}
}
Further in frameworks/base...
base/core/java/android/app/AppOpsManager.java
124: public static final int OP_POST_NOTIFICATION = 11;
Deeper in frameworks/base...
base/services/java/com/android/server/am/ActivityManagerService.java
2000: mAppOpsService = new AppOpsService(new File(systemDir, "appops.xml"));
So if you have root you can modify the /data/system/appops.xml. You may need to study the format by reading the code at: https://github.com/android/platform_frameworks_base/blob/master/core/java/android/app/AppOpsManager.java
I found a pretty long article here with some information that might help as well:
http://commonsware.com/blog/2013/07/26/app-ops-developer-faq.html

Change eBay search from US to UK

I am trying to change the search site that my eBay Android app searches in. At the moment, it searches the US site, but I would like it to search the UK site.
Here's my findingServiceClient class that I'm trying to make search the UK site, with the country code 3(UK, source).
As far as I can see I have set my code up to search the UK site, but it still seems to search the US.
any help would be appreciated, thanks.
public class FindingServiceClient {
// production
public static String eBayFindingServiceURLString = "http://svcs.ebay.com/services/search/FindingService/v1";
// sandbox
//public static String eBayFindingServiceURLString = "https://svcs.sandbox.ebay.com/services/search/FindingService/v1";
public static String eBayAppId = "ebay_app_id";
private static volatile FindingServicePortType_SOAPClient client = null;
public static String targetSiteid = "3";
public static FindingServicePortType_SOAPClient getSharedClient() {
if (client == null) {
synchronized(FindingServiceClient.class) {
if (client == null) {
client = new FindingServicePortType_SOAPClient();
client.setEndpointUrl(eBayFindingServiceURLString);
client.setSoapVersion(SOAPVersion.SOAP12); // ebay finding service supports SOAP 1.2
client.setContentType("application/soap+xml");
client.getAsyncHttpClient().addHeader("X-EBAY-API-SITE-ID", targetSiteid);
client.getAsyncHttpClient().addHeader("Accept", "application/soap+xml");
client.getAsyncHttpClient().addHeader("X-EBAY-SOA-SECURITY-APPNAME", eBayAppId);
client.getAsyncHttpClient().addHeader("X-EBAY-SOA-MESSAGE-PROTOCOL", "SOAP12");
client.getAsyncHttpClient().addHeader("X-EBAY-SOA-REQUEST-DATA-FORMAT", "SOAP");
}
}
}
return client;
}
}
The site that is searched is specified in the HTTP header X-EBAY-SOA-GLOBAL-ID. The value of this header is not a unique integer, such as 3, but a unique string, such as EBAY-US. To search the UK site you need to make the two below changes to your code and remove any reference to X-EBAY-API-SITE-ID.
public static String targetSiteid = "EBAY-GB";
client.getAsyncHttpClient().addHeader("X-EBAY-SOA-GLOBAL-ID", targetSiteid);
The eBay docs provide a complete list of HTTP headers and a table of site IDs mapped to global IDs.

android is it possible for an app to detect when it is running on emulator vs device

I develop a game that is heavily dependent upon timing, when I run it in the emulator it executes understandably slower than when I run it on my phone. This forces me to up all the "stats" in my game, so that I can actually "beat it" when I am developing - when Debugging, the game is unwinnable.
Is there a call, or variable, or something that I can use to determine whether I am currently running on the Emulator and not a device.
I've considered trying to detect if Framerate is low.
I've considered trying to read the "device name" from some sort of build in system field.
But neither seems like a very good method to pursue.
Any help would be great.
Use the Build.DEVICE value and compare to "sdk".
First idea:check the network operator, on the emulator, it's always equal to "Android". Not documented and just a guess that it will work everytime!
TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String networkOperator = tm.getNetworkOperatorName();
if("Android".equals(networkOperator)) {
// Emulator
}
else {
// Device
}
Second idea: the manufacturer:
public boolean isEmulator() {
return Build.MANUFACTURER.equals("unknown");
}
Third idea: seem th best one, check the debug key:
static final String DEBUGKEY =
"get the debug key from logcat after calling the function below once from the emulator";
public static boolean signedWithDebugKey(Context context, Class<?> cls)
{
boolean result = false;
try {
ComponentName comp = new ComponentName(context, cls);
PackageInfo pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(),PackageManager.GET_SIGNATURES);
Signature sigs[] = pinfo.signatures;
for ( int i = 0; i < sigs.length;i++)
Log.d(TAG,sigs[i].toCharsString());
if (DEBUGKEY.equals(sigs[0].toCharsString())) {
result = true;
Log.d(TAG,"package has been signed with the debug key");
} else {
Log.d(TAG,"package signed with a key other than the debug key");
}
} catch (android.content.pm.PackageManager.NameNotFoundException e) {
return false;
}
return result;
}
from here: How can I detect when an Android application is running in the emulator?
If you're using Google APIs, you want:
"google_sdk".equals( Build.PRODUCT );
If not, you'll want to use:
"sdk".equals( Build.PRODUCT );
The older (since deprecated) way to do this was to check ANDROID_ID, which is null on the AVD, but this doesn't work on API 7 and above:
// ONLY WORKS ON 2.1 AND BELOW
String android_id = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
if (android_id == null) {
// Emulator!
} else {
// Device
}
Dan S gave a good answer about how to detect when running on the emulator. However, a few tips:
Instead of relying on something in the SDK, why not just set up your own flag? Just keep a public final static boolean isEmulator that you change from true to false depending on the environment, and build your code with ifs and elses around it. The Build.DEVICE method is not 100% safe, since some rooted devices might have that borked.
Low framerate detection could be a good thing to implement. Given the wide range of Android devices, it might prove helpful on lower-end ones.

Categories

Resources