Skip to content

Commit

Permalink
adds new disableLogging in pages and entry
Browse files Browse the repository at this point in the history
adds new way to get log of pages
packageAssembler now honors param order and fixes glesVersion system feature issue
  • Loading branch information
patrickfav committed Feb 3, 2017
1 parent 115f11c commit 992db91
Show file tree
Hide file tree
Showing 31 changed files with 291 additions and 77 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Releases

## v0.5.0 (2017-02-04)

* adds feature to disable logging for entries or entire pages
* adds feature to get log of pages as StringBuilder
* fix showing null if uses-feature requires glEsVersion and has no name (used often for Google Maps)
### Migration from v0.4.x

* Use PageEntry.disableLogging() instead of Hood.get().createHeaderEntry(String,bool) to disable it in logging

## v0.4.4 (2017-01-30)

* minor demo app layout fix
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -533,4 +533,7 @@ 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.
limitations under the License.


Umstieg auf eine Amerikanische Tastatur
20 changes: 10 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ dependencies {

testCompile "junit:junit:$rootProject.ext.dependencies.junit"

debugCompile("at.favre.lib.hood:hood-extended:$rootProject.ext.versionNameDep")
releaseCompile("at.favre.lib.hood:hood-extended:$rootProject.ext.versionNameDep")

releaseNoopCompile("at.favre.lib.hood:hood-extended:$rootProject.ext.versionNameDep") {
exclude group: 'at.favre.lib.hood', module: 'hood-core'
releaseNoopCompile(group: 'at.favre.lib.hood', name: 'hood-core', version: rootProject.ext.versionNameDep,
classifier: 'noop', ext: 'aar', transitive: true)
}

//compile project(path: ':hood-extended')
// debugCompile("at.favre.lib.hood:hood-extended:$rootProject.ext.versionNameDep")
// releaseCompile("at.favre.lib.hood:hood-extended:$rootProject.ext.versionNameDep")
//
// releaseNoopCompile("at.favre.lib.hood:hood-extended:$rootProject.ext.versionNameDep") {
// exclude group: 'at.favre.lib.hood', module: 'hood-core'
// releaseNoopCompile(group: 'at.favre.lib.hood', name: 'hood-core', version: rootProject.ext.versionNameDep,
// classifier: 'noop', ext: 'aar', transitive: true)
// }

compile project(path: ':hood-extended')
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.android.support', module: 'support-v4'
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
android:name="android.hardware.sensor.accelerometer"
android:required="true"/>

<uses-feature
android:glEsVersion="0x00020000"
android:required="false"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/at/favre/app/hood/demo/DebugDarkActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.favre.app.hood.demo;

import android.content.pm.FeatureInfo;
import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.view.View;
Expand Down Expand Up @@ -27,6 +28,7 @@
import at.favre.lib.hood.util.defaults.DefaultButtonDefinitions;
import at.favre.lib.hood.util.defaults.DefaultConfigActions;
import at.favre.lib.hood.util.defaults.DefaultProperties;
import timber.log.Timber;

public class DebugDarkActivity extends PopHoodActivity {
private static final String TAG = DebugDarkActivity.class.getName();
Expand Down Expand Up @@ -72,7 +74,7 @@ public String getValue() {

firstPage.add(Hood.get().createPropertyEntry("MultiLine Test", "I am displaying text in a textview that appears to\nbe too long to fit into one screen. \nI need to make my TextView scrollable. How can i do\nthat? Here is the code\nbe too long to fit into one screen. \nI need to make my TextView scrollable. How can i do\nthat? Here is the code\ne too long to fit into one screen. \nI need to make my TextView scrollable. How can i do\nthat? Here is the code", true));

firstPage.add(Hood.get().createHeaderEntry("Misc Action", true));
firstPage.add(Hood.get().createHeaderEntry("Misc Action"));
PageUtil.addAction(firstPage, new ButtonDefinition("Test Loading", new OnClickAction() {
@Override
public void onClick(final View view, Map.Entry<CharSequence, String> value) {
Expand All @@ -88,6 +90,10 @@ public void run() {
}
}));

for (FeatureInfo featureInfo : getPackageManager().getSystemAvailableFeatures()) {
Timber.d(String.valueOf(featureInfo) + "\n");
}

PageUtil.addAction(firstPage, DefaultButtonDefinitions.getCrashAction());
PageUtil.addAction(firstPage, DefaultButtonDefinitions.getKillProcessAction(this), DefaultButtonDefinitions.getClearAppDataAction());
PageUtil.addAction(firstPage, HoodUtil.getConditionally(DefaultButtonDefinitions.getKillProcessAction(this), BuildConfig.DEBUG));
Expand Down Expand Up @@ -115,7 +121,7 @@ public void run() {
firstPage.add(DefaultProperties.createSectionAppVersionInfoFromBuildConfig(BuildConfig.class));
firstPage.add(new PackageInfoAssembler(PackageInfoAssembler.Type.SIGNATURE).createSection(this, false));
firstPage.add(DefaultProperties.createSectionTelephonyManger(this));
firstPage.add(Hood.get().createHeaderEntry("Settings", true));
firstPage.add(Hood.get().createHeaderEntry("Settings"));
firstPage.add(Hood.get().createActionEntry(new ButtonDefinition("Click me", new OnClickAction() {
@Override
public void onClick(View v, Map.Entry<CharSequence, String> value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Pages getPageData(@NonNull Pages pages) {

firstPage.add(Hood.get().createPropertyEntry("MultiLine Test", "I am displaying text in a textview that appears to\nbe too long to fit into one screen. \nI need to make my TextView scrollable. How can i do\nthat? Here is the code\nbe too long to fit into one screen. \nI need to make my TextView scrollable. How can i do\nthat? Here is the code\ne too long to fit into one screen. \nI need to make my TextView scrollable. How can i do\nthat? Here is the code", true));

firstPage.add(Hood.get().createHeaderEntry("Misc Action", true));
firstPage.add(Hood.get().createHeaderEntry("Misc Action"));
PageUtil.addAction(firstPage, new ButtonDefinition("Test Loading", new OnClickAction() {
@Override
public void onClick(final View view, Map.Entry<CharSequence, String> value) {
Expand Down Expand Up @@ -93,7 +93,7 @@ public void run() {
secondPage.add(DefaultProperties.createSectionStrictMode());
secondPage.add(DefaultProperties.createSectionBatteryInfo(this));
secondPage.add(DefaultProperties.createSectionAndroidDebugSettings(this));
secondPage.add(Hood.get().createHeaderEntry("Settings", true));
secondPage.add(Hood.get().createHeaderEntry("Settings"));

PageUtil.addAction(secondPage, DefaultButtonDefinitions.getGlobalSettingsAction(), DefaultButtonDefinitions.getNfcSettingsAction());
PageUtil.addAction(secondPage, DefaultButtonDefinitions.getNfcPaymentSettingsAction(), DefaultButtonDefinitions.getDevSettingsAction());
Expand All @@ -107,11 +107,10 @@ public void run() {
secondPage.add(new PackageInfoAssembler(PackageInfoAssembler.Type.APK_VERSION_INFO, PackageInfoAssembler.Type.APK_INSTALL_INFO).createSection(this, true));

Page thirdPage = pages.addNewPage("Package Manager");
thirdPage.add(new PackageInfoAssembler(PackageInfoAssembler.Type.APK_VERSION_INFO,
thirdPage.add(new PackageInfoAssembler(PackageInfoAssembler.Type.USES_FEATURE, PackageInfoAssembler.Type.APK_VERSION_INFO,
PackageInfoAssembler.Type.APK_INSTALL_INFO, PackageInfoAssembler.Type.ACTIVITIES,
PackageInfoAssembler.Type.PERMISSIONS, PackageInfoAssembler.Type.PROVIDER,
PackageInfoAssembler.Type.RECEIVERS, PackageInfoAssembler.Type.SERVICES,
PackageInfoAssembler.Type.SIGNATURE, PackageInfoAssembler.Type.USES_FEATURE).createSection(this, true));
PackageInfoAssembler.Type.SIGNATURE, PackageInfoAssembler.Type.PERMISSIONS, PackageInfoAssembler.Type.PROVIDER,
PackageInfoAssembler.Type.RECEIVERS, PackageInfoAssembler.Type.SERVICES, PackageInfoAssembler.Type.ACTIVITIES).createSection(this, true));

return pages;
}
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ task clean(type: Delete) {
}

ext {
versionNameApp = "0.4.4"
versionNameApp = "0.5.0"
versionNameLib = "$versionNameApp"
versionCode = getCiBuildNumber()
versionNameDep = "0.4.+"
versionNameDep = "0.+"


compileSdkVersion = 25
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ public interface HoodAPI {
*/
PageEntry<?> createHeaderEntry(CharSequence header);

/**
* Creates a header entry
*
* @param header as shown in ui
* @param hideInLog will omit it in log
*/
PageEntry<?> createHeaderEntry(CharSequence header, boolean hideInLog);

/**
* Creates a simple, non-interactive text message
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,17 @@ public interface Page {
void logPage();

/**
* Clears all the entries
* Clears all the entries attached to this view
*/
void removeEntries();

/**
* Disables any output or action when trying to log this page. Will disable logging on
* all attached page entries and every entry that gets added later. Affects calls like
* {@link #logPage()} and {@link PageEntry#toLogString()}
*/
void disableLogging();

/**
* The config should be passed to this class
* @return the currently set config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public interface PageEntry<T> {
@Nullable
String toLogString();

/**
* Disables any output when trying to log. {@link #toLogString()} will always
* return null after calling this method.
*/
void disableLogging();

/**
* This should refresh the UI content. Will be called by the framework.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ public interface Pages {
*/
void logPages();

/**
* Same as {@link #logPages()} but returns the string that would be logged instead
* @return the log of the page as {@link StringBuilder}
*/
StringBuilder getLogString();

/**
* The config should be passed to this class
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
Expand Down Expand Up @@ -137,11 +139,13 @@ public List<PageEntry<?>> getEntries(@NonNull Context context, @NonNull PackageI
}
}

private final EnumSet<Type> typeSet;
private final List<Type> typeList;
private final String packageName;

/**
* Same as {@link PackageInfoAssembler} constructor, but will use the current's packageName
* Same as {@link PackageInfoAssembler} constructor, but will use the current's packageName.
* Note that the order in which the type parameters are set will be honored, also it is possible
* to include a type multiple times.
*
* @param type must provide types - each type will request a certain packageManager info category (see {@link Type}
*/
Expand All @@ -158,7 +162,11 @@ public PackageInfoAssembler(@NonNull Type type, Type... types) {
*/
public PackageInfoAssembler(String packageName, @NonNull Type type, Type... types) {
this.packageName = packageName;
this.typeSet = EnumSet.of(type, types);
this.typeList = new LinkedList<>();
typeList.add(type);
if (types != null) {
typeList.addAll(Arrays.asList(types));
}
}

/**
Expand All @@ -185,13 +193,13 @@ public Section createSection(@Nullable Context context, boolean addSectionHeader
String targetPackageName = packageName == null ? context.getPackageName() : packageName;
try {
@SuppressWarnings("WrongConstant")
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), getRequiredRequestFlags(typeSet));
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), getRequiredRequestFlags(typeList));

if (packageInfo == null) {
throw new IllegalStateException("info was null");
}

for (Type type : typeSet) {
for (Type type : typeList) {
mainSection.add(Hood.ext().createSection(addSectionHeaders ? type.header : null, type.pageEntryProvider.getEntries(context, packageInfo)));
}
} catch (Exception e) {
Expand All @@ -202,10 +210,10 @@ public Section createSection(@Nullable Context context, boolean addSectionHeader
return mainSection.removeHeader();
}

private int getRequiredRequestFlags(EnumSet<Type> requestedTypes) {
private int getRequiredRequestFlags(List<Type> requestedTypes) {
int flags = 0;

for (Type requestedType : requestedTypes) {
EnumSet<Type> set = EnumSet.copyOf(requestedTypes);
for (Type requestedType : set) {
if (requestedType.requestFlag != null) {
flags |= requestedType.requestFlag;
}
Expand Down Expand Up @@ -406,8 +414,19 @@ public static List<PageEntry<?>> createPmDeclaredSystemFeatureInfo(@NonNull Cont
if (packageInfo.reqFeatures != null && packageInfo.reqFeatures.length > 0) {
for (FeatureInfo reqFeature : packageInfo.reqFeatures) {
boolean required = reqFeature.flags == FeatureInfo.FLAG_REQUIRED;
String fullLabel = reqFeature.name + (required ? " (req)" : "");
featureMap.put(Hood.ext().createFullLabel(fullLabel.replace("android.hardware.", ""), fullLabel), reqFeature.name);
String fullLabel;
String id;
if ((reqFeature.name == null || reqFeature.name.trim().isEmpty())
&& reqFeature.getGlEsVersion() != null && !reqFeature.getGlEsVersion().isEmpty()) {
fullLabel = "glEsVersion " + reqFeature.getGlEsVersion();
id = String.valueOf(reqFeature.reqGlEsVersion);
} else {
fullLabel = reqFeature.name;
id = reqFeature.name;
}

fullLabel += (required ? " (req)" : "");
featureMap.put(Hood.ext().createFullLabel(fullLabel.replace("android.hardware.", ""), fullLabel), id);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import android.Manifest;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ConfigurationInfo;
import android.content.pm.PackageManager;
import android.os.BatteryManager;
import android.os.Build;
Expand Down Expand Up @@ -354,8 +356,16 @@ public String getValue() {
public static List<PageEntry<?>> createSystemFeatureInfo(@Nullable Context context, Map<CharSequence, String> labelSystemFeatureMap) {
List<PageEntry<?>> entries = new ArrayList<>();
if (context != null) {

for (Map.Entry<CharSequence, String> entry : labelSystemFeatureMap.entrySet()) {
entries.add(Hood.get().createPropertyEntry(entry.getKey(), String.valueOf(context.getPackageManager().hasSystemFeature(entry.getValue()))));
boolean supported;
if (entry.getValue().matches("^-?\\d+$")) {
final ConfigurationInfo configurationInfo = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getDeviceConfigurationInfo();
supported = configurationInfo.reqGlEsVersion >= Integer.valueOf(entry.getValue());
} else {
supported = context.getPackageManager().hasSystemFeature(entry.getValue());
}
entries.add(Hood.get().createPropertyEntry(entry.getKey(), String.valueOf(supported)));
}
}
return entries;
Expand Down
5 changes: 0 additions & 5 deletions hood-core/src/noop/java/at/favre/lib/hood/noop/HoodNoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ public PageEntry<?> createHeaderEntry(CharSequence header) {
return placeholderPageEntry;
}

@Override
public PageEntry<?> createHeaderEntry(CharSequence header, boolean hideInLog) {
return placeholderPageEntry;
}

@Override
public PageEntry<?> createMessageEntry(CharSequence message) {
return placeholderPageEntry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public String toLogString() {
return null;
}

@Override
public void disableLogging() {
//no-op
}

@Override
public void refresh() {
//no-op
Expand Down
6 changes: 6 additions & 0 deletions hood-core/src/noop/java/at/favre/lib/hood/noop/PageNoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public String getTitle() {
return placeHolderTitle;
}

@NonNull
@Override
public List<PageEntry> getEntries() {
return Collections.emptyList();
Expand Down Expand Up @@ -65,6 +66,11 @@ public void removeEntries() {
//no-op
}

@Override
public void disableLogging() {
//no-op
}

@NonNull
@Override
public Config getConfig() {
Expand Down
5 changes: 5 additions & 0 deletions hood-core/src/noop/java/at/favre/lib/hood/noop/PagesNoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public void logPages() {
//no-op
}

@Override
public StringBuilder getLogString() {
return new StringBuilder();
}

@NonNull
@Override
public Config getConfig() {
Expand Down
Loading

0 comments on commit 992db91

Please sign in to comment.